Advertisement
Guest User

Untitled

a guest
Sep 1st, 2016
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.98 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
  136.  
  137. #Include <file.au3>
  138. #include <EditConstants.au3>
  139. #include <GUIConstantsEx.au3>
  140. #include <StaticConstants.au3>
  141. #include <ButtonConstants.au3>
  142. #include <WindowsConstants.au3>
  143.  
  144. Global $oMyRet[2]
  145. Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
  146.  
  147. ;GUI
  148. $Form1 = GUICreate("Form1", 317, 168, -1, -1)
  149. $Label = GUICtrlCreateLabel("Label", 32, 8, 253, 29)
  150. GUICtrlSetFont(-1, 15, 800, 4, "MS Sans Serif")
  151. $Input1 = GUICtrlCreateInput("Input1", 68, 48, 185, 24)
  152. GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
  153. $Input2 = GUICtrlCreateInput("Input2", 68, 80, 185, 24, BitOR($GUI_SS_DEFAULT_INPUT,$ES_PASSWORD))
  154. GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif")
  155. $Button = GUICtrlCreateButton("Button", 102, 120, 113, 33)
  156. GUISetState(@SW_SHOW)
  157. ;GUIend
  158.  
  159. While 1
  160. $nMsg = GUIGetMsg()
  161. Switch $nMsg
  162. Case $GUI_EVENT_CLOSE
  163. Exit
  164. Case $Button
  165. _Mail()
  166. EndSwitch
  167. WEnd
  168.  
  169.  
  170. Func _Mail()
  171. ;##################################
  172. ; Variables
  173. ;##################################
  174. Local $SmtpServer = "smtp.email.com" ; address for the smtp-server to use - REQUIRED
  175. Local $FromName = "Name" ; name from who the email was sent
  176. Local $FromAddress = "From@email.com" ; address from where the mail should come
  177. Local $ToAddress = "To@email.com" ; destination address of the email - REQUIRED
  178. Local $Subject = "TEST" ; subject from the email - can be anything you want it to be
  179. Local $Body = "TEST TEST TEST" ; the messagebody from the mail - can be left blank but then you get a blank mail
  180. Local $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
  181. Local $CcAddress = "" ; address for cc - leave blank if not needed
  182. Local $BccAddress = "" ; address for bcc - leave blank if not needed
  183. Local $Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
  184. Local $Username = "From@email.com" ; username for the account used from where the mail gets sent - REQUIRED
  185. Local $Password = "Password" ; password for the account used from where the mail gets sent - REQUIRED
  186. Local $IPPort = 465 ; port used for sending the mail
  187. Local $ssl = 1 ; enables/disables secure socket layer sending - put to 1 if using httpS
  188. ;~ $IPPort=465 ; GMAIL port used for sending the mail
  189. ;~ $ssl=1 ; GMAILenables/disables secure socket layer sending - put to 1 if using httpS
  190.  
  191. ;##################################
  192. ; Script
  193. ;##################################
  194. $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl)
  195. If @error Then
  196. MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
  197. EndIf
  198. EndFunc
  199.  
  200. ; The UDF
  201. 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)
  202. Local $objEmail = ObjCreate("CDO.Message")
  203. $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
  204. $objEmail.To = $s_ToAddress
  205. Local $i_Error = 0
  206. Local $i_Error_desciption = ""
  207. If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
  208. If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
  209. $objEmail.Subject = $s_Subject
  210. If StringInStr($as_Body, "<") And StringInStr($as_Body, ">") Then
  211. $objEmail.HTMLBody = $as_Body
  212. Else
  213. $objEmail.Textbody = $as_Body & @CRLF
  214. EndIf
  215. If $s_AttachFiles <> "" Then
  216. Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
  217. For $x = 1 To $S_Files2Attach[0]
  218. $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
  219. ;~ ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console
  220. If FileExists($S_Files2Attach[$x]) Then
  221. ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
  222. $objEmail.AddAttachment($S_Files2Attach[$x])
  223. Else
  224. ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
  225. SetError(1)
  226. Return 0
  227. EndIf
  228. Next
  229. EndIf
  230. $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  231. $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
  232. If Number($IPPort) = 0 then $IPPort = 25
  233. $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
  234. ;Authenticated SMTP
  235. If $s_Username <> "" Then
  236. $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
  237. $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
  238. $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
  239. EndIf
  240. If $ssl Then
  241. $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
  242. EndIf
  243. ;Update settings
  244. $objEmail.Configuration.Fields.Update
  245. ; Set Email Importance
  246. Switch $s_Importance
  247. Case "High"
  248. $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "High"
  249. Case "Normal"
  250. $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Normal"
  251. Case "Low"
  252. $objEmail.Fields.Item ("urn:schemas:mailheader:Importance") = "Low"
  253. EndSwitch
  254. $objEmail.Fields.Update
  255. ; Sent the Message
  256. $objEmail.Send
  257. If @error Then
  258. SetError(2)
  259. Return $oMyRet[1]
  260. EndIf
  261. $objEmail=""
  262. EndFunc ;==>_INetSmtpMailCom
  263. ;
  264. ;
  265. ; Com Error Handler
  266. Func MyErrFunc()
  267. Local $HexNumber = Hex($oMyError.number, 8)
  268. $oMyRet[0] = $HexNumber
  269. $oMyRet[1] = StringStripWS($oMyError.description, 3)
  270. ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
  271. SetError(1); something to check for when this function returns
  272. Return
  273. EndFunc ;==>MyErrFunc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement