#Region ;************ Includes ************
#include <File.au3>
#EndRegion ;************ Includes ************
Global $s_SmtpServer = "smtp.online.nl"
Global $s_FromName = "Dm"
Global $s_FromAddress = "[email protected]"
Global $s_ToAddress = "[email protected]"
Global $s_Subject = "subj"
Global $s_Body = "test"
Global $s_AttachFiles = ""
Global $s_CcAddress, $s_BccAddress
Global $s_Username = "[email protected]"
Global $s_Password = "password"
Global $IPPort = 25
Global $ssl, $oMyRet[2], $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
_INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $s_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
If @error Then MsgBox(16,"Error", "Error sending message. Error code: " & @error )
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $s_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "", $IPPort = 25, $ssl = 0)
Local $objEmail = ObjCreate("CDO.Message")
If Not IsObj($objEmail) Then Return SetError(1, 0, 0)
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress ;##################################################################
Local $i_Error = 0
Local $i_Error_desciption = ""
If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.Bcc = $s_BccAddress
$objEmail.Subject = $s_Subject
If StringInStr($s_Body, "<") And StringInStr($s_Body, ">") Then
$objEmail.HTMLBody = $s_Body
Else
$objEmail.Textbody = $s_Body & @CRLF
EndIf
If $s_AttachFiles <> "" Then
Local $S_Files2Attach = StringSplit($s_AttachFiles, ";")
For $x = 1 To $S_Files2Attach[0]
$S_Files2Attach[$x] = _PathFull($S_Files2Attach[$x])
If FileExists($S_Files2Attach[$x]) Then
$objEmail.AddAttachment($S_Files2Attach[$x])
Else
$i_Error_desciption = $i_Error_desciption & @LF & 'File not found to attach: ' & $S_Files2Attach[$x]
Return SetError(1, 0, 0)
EndIf
Next
EndIf
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $s_SmtpServer
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $IPPort
If $s_Username <> "" Then
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $s_Username
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $s_Password
EndIf
If $ssl Then
$objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
EndIf
$objEmail.Configuration.Fields.Update
$objEmail.Send
If @error Then Return SetError(2, 0, $oMyRet[1])
EndFunc ;==>_INetSmtpMailCom