Posted By

qoli on 10/04/11


Tagged


Versions (?)

Mailto


 / Published in: AutoIt
 

  1. #Region ;**** 参数创建于 ACNWrapper_GUI ****
  2. #AutoIt3Wrapper_Icon=..\..\..\..\素材\Icons\Minicons_by_Asher\Mail.ico
  3. #AutoIt3Wrapper_UseX64=n
  4. #EndRegion ;**** 参数创建于 ACNWrapper_GUI ****
  5.  
  6.  
  7. ;
  8. ;##################################
  9. ; Include
  10. ;##################################
  11. #include<file.au3>
  12. ;##################################
  13. ; Variables
  14. ;##################################
  15. $SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED
  16. $FromName = "Qoli" ; name from who the email was sent
  17. $FromAddress = "E-MAIL" ; address from where the mail should come
  18. $ToAddress = "?@bannka.com" ; destination address of the email - REQUIRED
  19. WinClose("Windows Snapshot Maker v3.5")
  20. $Subject = InputBox("发微博", "微博内容?!", "") ; subject from the email - can be anything you want it to be
  21. ToolTip($Subject, 50, 50, 'Bannka - 发送中...', 1, 4)
  22.  
  23.  
  24.  
  25. $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail
  26. $AttachFiles = $CmdLine[1] ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
  27. $CcAddress = "" ; address for cc - leave blank if not needed
  28. $BccAddress = "" ; address for bcc - leave blank if not needed
  29. $Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
  30. $Username = "USER" ; username for the account used from where the mail gets sent - REQUIRED
  31. $Password = "PASS" ; password for the account used from where the mail gets sent - REQUIRED
  32. $IPPort = 25 ; port used for sending the mail
  33. ;$ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS
  34. $IPPort = 465 ; GMAIL port used for sending the mail
  35. $ssl = 1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
  36.  
  37. ;##################################
  38. ; Script
  39. ;##################################
  40. Global $oMyRet[2]
  41. Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
  42. $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
  43. MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
  44. ;
  45. ; The UDF
  46. 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)
  47. Local $objEmail = ObjCreate("CDO.Message")
  48. $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
  49. $objEmail.To = $s_ToAddress
  50. $objEmail.BodyPart.Charset = "GB2312"
  51. $objEmail.HTMLBodyPart.Charset = "GB2312"
  52. Local $i_Error = 0
  53. Local $i_Error_desciption = ""
  54. If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
  55. If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
  56. $objEmail.Subject = $s_Subject
  57. If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
  58. $objEmail.HTMLBody = $as_Body
  59. $objEmail.Textbody = $as_Body & @CRLF
  60. If $s_AttachFiles <> "" Then
  61. Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
  62. For $x = 1 To $S_Files2Attach[0]
  63. $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
  64. ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
  65. If FileExists($S_Files2Attach[$x]) Then
  66. ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
  67. $objEmail.AddAttachment($S_Files2Attach[$x])
  68. ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
  69. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  70. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
  71. If Number($IPPort) = 0 Then $IPPort = 25
  72. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
  73. ;Authenticated SMTP
  74. If $s_Username <> "" Then
  75. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  76. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
  77. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
  78. If $ssl Then
  79. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  80. ;Update settings
  81. $objEmail.Configuration.Fields.Update
  82. ; Set Email Importance
  83. Switch $s_Importance
  84. Case "High"
  85. $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High"
  86. Case "Normal"
  87. $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal"
  88. Case "Low"
  89. $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low"
  90. $objEmail.Fields.Update
  91. ; Sent the Message
  92. $objEmail.Send
  93. Return $oMyRet[1]
  94. $objEmail = ""
  95. EndFunc ;==>_INetSmtpMailCom
  96. ;
  97. ;
  98. ; Com Error Handler
  99. Func MyErrFunc()
  100. $HexNumber = Hex($oMyError.number, 8)
  101. $oMyRet[0] = $HexNumber
  102. $oMyRet[1] = StringStripWS($oMyError.description, 3)
  103. ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
  104. SetError(1); something to check for when this function returns
  105. EndFunc ;==>MyErrFunc

Report this snippet  

You need to login to post a comment.