Advertisement
Guest User

Untitled

a guest
Apr 28th, 2017
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.04 KB | None | 0 0
  1. #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
  2. ;~ #AutoIt3Wrapper_Run_Debug_Mode=Y ;(Y/N) Run Script with console debugging. Default=N
  3.  
  4. #Region INCLUDE
  5. ;##################################
  6. ; Include
  7. ;##################################
  8. #include <file.au3>
  9. #EndRegion INCLUDE
  10.  
  11. #Region Variables
  12. ;##################################
  13. ; Variables
  14. ;##################################
  15. Global Enum _
  16. $g__INetSmtpMailCom_ERROR_FileNotFound = 1, _
  17. $g__INetSmtpMailCom_ERROR_Send, _
  18. $g__INetSmtpMailCom_ERROR_ObjectCreation, _
  19. $g__INetSmtpMailCom_ERROR_COUNTER
  20.  
  21. Global Const $g__cdoSendUsingPickup = 1 ; Send message using the local SMTP service pickup directory.
  22. Global Const $g__cdoSendUsingPort = 2 ; Send the message using the network (SMTP over the network). Must use this to use Delivery Notification
  23.  
  24. Global Const $g__cdoAnonymous = 0 ; Do not authenticate
  25. Global Const $g__cdoBasic = 1 ; basic (clear-text) authentication
  26. Global Const $g__cdoNTLM = 2 ; NTLM
  27.  
  28. ; Delivery Status Notifications
  29. Global Const $g__cdoDSNDefault = 0 ; None
  30. Global Const $g__cdoDSNNever = 1 ; None
  31. Global Const $g__cdoDSNFailure = 2 ; Failure
  32. Global Const $g__cdoDSNSuccess = 4 ; Success
  33. Global Const $g__cdoDSNDelay = 8 ; Delay
  34. Global Const $g__cdoDSNSuccessFailOrDelay = 14 ; Success, failure or delay
  35. #EndRegion Variables
  36.  
  37. #Region Example Script
  38. ;##################################
  39. ; Example Script
  40. ;##################################
  41. ;~ _Example()
  42.  
  43. Func _Example()
  44. Local $sSmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED
  45. Local $sFromName = "Name" ; name from who the email was sent
  46. Local $sFromAddress = "your@Email.Address.com" ; address from where the mail should come
  47. Local $sToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED
  48. Local $sSubject = "Userinfo" ; subject from the email - can be anything you want it to be
  49. Local $sBody = "" ; the messagebody from the mail - can be left blank but then you get a blank mail
  50. Local $sAttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed
  51. Local $sCcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed
  52. Local $sBccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed
  53. Local $sImportance = "Normal" ; Send message priority: "High", "Normal", "Low"
  54. Local $sUsername = "******" ; username for the account used from where the mail gets sent - REQUIRED
  55. Local $sPassword = "********" ; password for the account used from where the mail gets sent - REQUIRED
  56. Local $iIPPort = 25 ; port used for sending the mail
  57. Local $bSSL = False ; enables/disables secure socket layer sending - set to True if using httpS
  58. ; Local $iIPPort = 465 ; GMAIL port used for sending the mail
  59. ; Local $bSSL = True ; GMAIL enables/disables secure socket layer sending - set to True if using httpS
  60.  
  61. Local $bIsHTMLBody = False
  62. Local $iDSNOptions = $g__cdoDSNDefault
  63.  
  64. Local $rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $sAttachFiles, $sCcAddress, $sBccAddress, $sImportance, $sUsername, $sPassword, $iIPPort, $bSSL, $bIsHTMLBody, $iDSNOptions)
  65. If @error Then
  66. MsgBox(0, "_INetSmtpMailCom(): Error sending message", _
  67. "Error code: " & @error & @CRLF & @CRLF & _
  68. "Error Hex Number: " & _INetSmtpMailCom_ErrHexNumber() & @CRLF & @CRLF & _
  69. "Description: " & _INetSmtpMailCom_ErrDescription() & @CRLF & @CRLF & _
  70. "Description (rc): " & $rc & @CRLF & @CRLF & _
  71. "ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() _
  72. )
  73. ConsoleWrite("### COM Error ! Number: " & _INetSmtpMailCom_ErrHexNumber() & " ScriptLine: " & _INetSmtpMailCom_ErrScriptLine() & " Description:" & _INetSmtpMailCom_ErrDescription() & @LF)
  74. EndIf
  75.  
  76. EndFunc ;==>_Example
  77.  
  78. #EndRegion Example Script
  79.  
  80. #Region UDF Functions
  81. ; The UDF
  82. ; #FUNCTION# ====================================================================================================================
  83. ; Name ..........: _INetSmtpMailCom
  84. ; Description ...:
  85. ; Syntax ........: _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress[, $s_Subject = ""[, $as_Body = ""[,
  86. ; $s_AttachFiles = ""[, $s_CcAddress = ""[, $s_BccAddress = ""[, $s_Importance = "Normal"[, $s_Username = ""[,
  87. ; $s_Password = ""[, $IPPort = 25[, $bSSL = False[, $bIsHTMLBody = False[, $iDSNOptions = $g__cdoDSNDefault]]]]]]]]]]]])
  88. ; Parameters ....: $s_SmtpServer - A string value.
  89. ; $s_FromName - A string value.
  90. ; $s_FromAddress - A string value.
  91. ; $s_ToAddress - A string value.
  92. ; $s_Subject - [optional] A string value. Default is "".
  93. ; $s_Body - [optional] A string value. Default is "".
  94. ; $s_AttachFiles - [optional] A string value. Default is "".
  95. ; $s_CcAddress - [optional] A string value. Default is "".
  96. ; $s_BccAddress - [optional] A string value. Default is "".
  97. ; $s_Importance - [optional] A string value. Default is "Normal".
  98. ; $s_Username - [optional] A string value. Default is "".
  99. ; $s_Password - [optional] A string value. Default is "".
  100. ; $IPPort - [optional] An integer value. Default is 25.
  101. ; $bSSL - [optional] A binary value. Default is False.
  102. ; $bIsHTMLBody - [optional] A binary value. Default is False.
  103. ; $iDSNOptions - [optional] An integer value. Default is $g__cdoDSNDefault.
  104. ; Return values .: None
  105. ; Author ........: Jos
  106. ; Modified ......: mLipok
  107. ; Remarks .......:
  108. ; Related .......: http://www.autoitscript.com/forum/topic/23860-smtp-mailer-that-supports-html-and-attachments/
  109. ; Link ..........: http://www.autoitscript.com/forum/topic/167292-smtp-mailer-udf/
  110. ; Example .......: Yes
  111. ; ===============================================================================================================================
  112. Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Importance = "Normal", $s_Username = "", $s_Password = "", $IPPort = 25, $bSSL = False, $bIsHTMLBody = False, $iDSNOptions = $g__cdoDSNDefault)
  113. ; init Error Handler
  114. _INetSmtpMailCom_ErrObjInit()
  115.  
  116. Local $objEmail = ObjCreate("CDO.Message")
  117. If Not IsObj($objEmail) Then Return SetError($g__INetSmtpMailCom_ERROR_ObjectCreation, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription())
  118.  
  119. ; Clear previous Err information
  120. _INetSmtpMailCom_ErrHexNumber(0)
  121. _INetSmtpMailCom_ErrDescription('')
  122. _INetSmtpMailCom_ErrScriptLine('')
  123.  
  124. $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
  125. $objEmail.To = $s_ToAddress
  126.  
  127. If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
  128. If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
  129. $objEmail.Subject = $s_Subject
  130.  
  131. ; Select whether or not the content is sent as plain text or HTM
  132. If $bIsHTMLBody Then
  133. $objEmail.Textbody = $s_Body & @CRLF
  134. Else
  135. $objEmail.HTMLBody = $s_Body
  136. EndIf
  137.  
  138. ; Add Attachments
  139. If $s_AttachFiles <> "" Then
  140. Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
  141. For $x = 1 To $S_Files2Attach[0]
  142. $S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
  143. If FileExists($S_Files2Attach[$x]) Then
  144. ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF)
  145. $objEmail.AddAttachment($S_Files2Attach[$x])
  146. Else
  147. ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF)
  148. Return SetError($g__INetSmtpMailCom_ERROR_FileNotFound, 0, 0)
  149. EndIf
  150. Next
  151. EndIf
  152.  
  153. ; Set Email Configuration
  154. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $g__cdoSendUsingPort
  155. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
  156. If Number($IPPort) = 0 Then $IPPort = 25
  157. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
  158. ;Authenticated SMTP
  159. If $s_Username <> "" Then
  160. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = $g__cdoBasic
  161. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
  162. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
  163. EndIf
  164. $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = $bSSL
  165.  
  166. ;Update Configuration Settings
  167. $objEmail.Configuration.Fields.Update
  168.  
  169. ; Set Email Importance
  170. Switch $s_Importance
  171. Case "High"
  172. $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High"
  173. Case "Normal"
  174. $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal"
  175. Case "Low"
  176. $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low"
  177. EndSwitch
  178.  
  179. ; Set DSN options
  180. If $iDSNOptions <> $g__cdoDSNDefault And $iDSNOptions <> $g__cdoDSNNever Then
  181. $objEmail.DSNOptions = $iDSNOptions
  182. $objEmail.Fields.Item("urn:schemas:mailheader:disposition-notification-to") = $s_FromAddress
  183. ;~ $objEmail.Fields.Item("urn:schemas:mailheader:return-receipt-to") = $s_FromAddress
  184. EndIf
  185.  
  186. ; Update Importance and Options fields
  187. $objEmail.Fields.Update
  188.  
  189. ; Sent the Message
  190. $objEmail.Send
  191.  
  192. If @error Then
  193. _INetSmtpMailCom_ErrObjCleanUp()
  194. Return SetError($g__INetSmtpMailCom_ERROR_Send, Dec(_INetSmtpMailCom_ErrHexNumber()), _INetSmtpMailCom_ErrDescription())
  195. EndIf
  196.  
  197. ; CleanUp
  198. $objEmail = ""
  199. _INetSmtpMailCom_ErrObjCleanUp()
  200.  
  201. EndFunc ;==>_INetSmtpMailCom
  202.  
  203. ;
  204. ; Com Error Handler
  205. Func _INetSmtpMailCom_ErrObjInit($bParam = Default)
  206. Local Static $oINetSmtpMailCom_Error = Default
  207. If $bParam == 'CleanUp' And $oINetSmtpMailCom_Error <> Default Then
  208. $oINetSmtpMailCom_Error = ''
  209. Return $oINetSmtpMailCom_Error
  210. EndIf
  211. If $oINetSmtpMailCom_Error = Default Then
  212. $oINetSmtpMailCom_Error = ObjEvent("AutoIt.Error", "_INetSmtpMailCom_ErrFunc")
  213. EndIf
  214. Return $oINetSmtpMailCom_Error
  215. EndFunc ;==>_INetSmtpMailCom_ErrObjInit
  216.  
  217. Func _INetSmtpMailCom_ErrObjCleanUp()
  218. _INetSmtpMailCom_ErrObjInit('CleanUp')
  219. EndFunc ;==>_INetSmtpMailCom_ErrObjCleanUp
  220.  
  221. Func _INetSmtpMailCom_ErrHexNumber($vData = Default)
  222. Local Static $vReturn = 0
  223. If $vData <> Default Then $vReturn = $vData
  224. Return $vReturn
  225. EndFunc ;==>_INetSmtpMailCom_ErrHexNumber
  226.  
  227. Func _INetSmtpMailCom_ErrDescription($sData = Default)
  228. Local Static $sReturn = ''
  229. If $sData <> Default Then $sReturn = $sData
  230. Return $sReturn
  231. EndFunc ;==>_INetSmtpMailCom_ErrDescription
  232.  
  233. Func _INetSmtpMailCom_ErrScriptLine($iData = Default)
  234. Local Static $iReturn = ''
  235. If $iData <> Default Then $iReturn = $iData
  236. Return $iReturn
  237. EndFunc ;==>_INetSmtpMailCom_ErrScriptLine
  238.  
  239. Func _INetSmtpMailCom_ErrFunc()
  240. _INetSmtpMailCom_ErrObjInit()
  241. _INetSmtpMailCom_ErrHexNumber(Hex(_INetSmtpMailCom_ErrObjInit().number, 8))
  242. _INetSmtpMailCom_ErrDescription(StringStripWS(_INetSmtpMailCom_ErrObjInit().description, 3))
  243. _INetSmtpMailCom_ErrScriptLine(_INetSmtpMailCom_ErrObjInit().ScriptLine)
  244. SetError(1); something to check for when this function returns
  245. Return
  246. EndFunc ;==>_INetSmtpMailCom_ErrFunc
  247.  
  248. #EndRegion UDF Functions
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement