Advertisement
Guest User

Untitled

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