#Region переменные
$sSmtpServer = "smtp.gmail.com"
$sFromName = "kelvin.kelford"
$sFromAddress = "[email protected]"
$sUsername = "kelvin.kelford"
$sPassword = "Password"
$sSubject = "Тема"
$sBody = "Текст письма"
$sToAddress = "[email protected]"
$iIPPort = 465
$iSsl = 1
Dim $aAttach[0] ; Массив прикрепляемых файлов
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
#EndRegion
$rc = _INetSmtpMailCom($sSmtpServer, $sFromName, $sFromAddress, $sToAddress, $sSubject, $sBody, $aAttach, Default, $sUsername, $sPassword, $iIPPort, $iSsl)
If @error Then
MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc)
EndIf
Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $a_Attach = "", $s_Importance="Normal", $s_Username = "", $s_Password = "", $IPPort = 465, $ssl = True)
Local $objEmail = ObjCreate("CDO.Message"), $i_Error = 0, $i_Error_desciption = ""
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/languagecode") = 1049
$objEmail.BodyPart.CharSet = "utf-8"
$objEmail.BodyPart.ContentTransferEncoding = "quoted-printable"
$objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'
$objEmail.To = $s_ToAddress
$objEmail.Subject = $s_Subject
; Можно отправлять в формате HTML
;$objEmail.HTMLBody = $as_Body
$objEmail.TextBody = $as_Body
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/usemessageresponsetext") = True
$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
$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
If UBound($a_Attach) > 0 Then
For $j = 0 To UBound($a_Attach)-1
If FileExists($a_Attach[$j]) Then
$objEmail.AddAttachment ($aAttach[$j])
Else
Exit MsgBox(4096, "", "Файл " & $a_Attach[$j] & " не найден")
EndIf
Next
EndIf
If $ssl Then
$objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
EndIf
$objEmail.Configuration.Fields.Update
$objEmail.Fields.Update
$objEmail.Send
If @error Then
SetError(2)
Return $oMyRet[1]
EndIf
$objEmail=""
EndFunc ;==>_INetSmtpMailCom
Func MyErrFunc()
$HexNumber = Hex($oMyError.number, 8)
$oMyRet[0] = $HexNumber
$oMyRet[1] = StringStripWS($oMyError.description, 3)
ConsoleWrite("### COM Error ! Number: " & $HexNumber & " ScriptLine: " & $oMyError.scriptline & " Description:" & $oMyRet[1] & @LF)
SetError(1); something to check for when this function returns
Return
EndFunc ;==>MyErrFunc