Darksider3

lol

Jul 31st, 2010
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 4.97 KB | None | 0 0
  1. ; Script Start - Add your code below here
  2. ;
  3. ;##################################
  4. ; Include
  5. ;##################################
  6. #include<file.au3>
  7. ;##################################
  8. ; Variables
  9. ;##################################
  10. $SmtpServer = "" ; address for the smtp-server to use - REQUIRED
  11. $FromName = "" ; name from who the email was sent
  12. $FromAddress = "" ; address from where the mail should come
  13. $ToAddress = "" ; destination address of the email - REQUIRED
  14. $Subject = "" ; subject from the email - can be anything you want it to be
  15. $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail
  16. $AttachFiles = "" ; the file you want to attach- leave blank if not needed
  17. $CcAddress = "" ; address for cc - leave blank if not needed
  18. $BccAddress = "" ; address for bcc - leave blank if not needed
  19. $Importance = "" ; Send message priority: "High", "Normal", "Low"
  20. $Username = "" ; username for the account used from where the mail gets sent - REQUIRED
  21. $Password = "" ; password for the account used from where the mail gets sent - REQUIRED
  22. $IPPort = 25 ; port used for sending the mail
  23. $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS
  24. ;~ $IPPort=465                          ; GMAIL port used for sending the mail
  25. ;~ $ssl=1                               ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
  26.  
  27.  
  28. ;##################################
  29. ; Script
  30. ;##################################
  31. Global $oMyRet[2]
  32. Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
  33.  
  34.  
  35. $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
  36.  
  37. If @error Then
  38.     MsgBox(0, "Error sending message", "Error code:" & @error & "  Description:" & $rc)
  39.     Exit
  40. EndIf
  41.  
  42. ;
  43. ; The UDF
  44. Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
  45.     Local $objEmail = ObjCreate("CDO.Message")
  46.     $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
  47.     $objEmail.To = $s_ToAddress
  48.     Local $i_Error = 0
  49.     Local $i_Error_desciption = ""
  50.     If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
  51.     If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
  52.     $objEmail.Subject = $s_Subject
  53.     If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
  54.         $objEmail.HTMLBody = $as_Body
  55.     Else
  56.         $objEmail.Textbody = $as_Body & @CRLF
  57.     EndIf
  58.     If $s_AttachFiles <> "" Then
  59.         Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
  60.         For $x = 1 To $S_Files2Attach[0]
  61.             $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
  62.             ConsoleWrite('@@ Debug(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
  63.             If FileExists($S_Files2Attach[$x]) Then
  64.                 $objEmail.AddAttachment($S_Files2Attach[$x])
  65.             Else
  66.                 ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
  67.                 SetError(1)
  68.                 Return 0
  69.             EndIf
  70.         Next
  71.     EndIf
  72.     $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  73.     $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
  74.     If Number($IPPort) = 0 Then $IPPort = 25
  75.     $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
  76.     ;Authenticated SMTP
  77.     If $s_Username <> "" Then
  78.         $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  79.         $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
  80.         $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
  81.     EndIf
  82.     If $ssl Then
  83.         $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  84.     EndIf
  85.     ;Update settings
  86.     $objEmail.Configuration.Fields.Update
  87.     ; Set Email Importance
  88.     Switch $s_Importance
  89.         Case "High"
  90.             $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High"
  91.         Case "Normal"
  92.             $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal"
  93.         Case "Low"
  94.             $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low"
  95.     EndSwitch
  96.     $objEmail.Fields.Update
  97.     ; Sent the Message
  98.     $objEmail.Send
  99.     If @error Then
  100.         SetError(2)
  101.         Return $oMyRet[1]
  102.     EndIf
  103.     $objEmail = ""
  104. EndFunc   ;==>_INetSmtpMailCom
  105. ;
  106. ;
  107. ; Com Error Handler
  108. Func MyErrFunc()
  109.     $HexNumber = Hex($oMyError.number, 8)
  110.     $oMyRet[0] = $HexNumber
  111.     $oMyRet[1] = StringStripWS($oMyError.description, 3)
  112.     ConsoleWrite("### COM Error !  Number: " & $HexNumber & "   ScriptLine: " & $oMyError.scriptline & "   Description:" & $oMyRet[1] & @LF)
  113.     SetError(1); something to check for when this function returns
  114.     Return
  115. EndFunc   ;==>MyErrFunc
Add Comment
Please, Sign In to add comment