#include #include #include #include ;================================== ; Email Variables ;================================== Global $s_eMail_SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED Global $s_eMail_FromName = "Test email c/o " & @UserName ; name from who the email was sent Global $s_eMail_FromAddress = "ewilsonatsunstarems@gmail.com" ; address from where the mail should come Global $s_eMail_ToAddress = "ewilson@sunstarems.com" ; destination address of the email - REQUIRED Global $s_eMail_Subject = "Testing the Subject Line of _INetSmtpMailCom" ;recapture this after SQL is read ; subject from the email - can be anything you want it to be Global $s_eMail_Body = "Sent using _INetSmtpMailCom " ;"" ; the messagebody from the mail - can be left blank but then you get a blank mail Global $s_eMail_AttachFiles = "" ;"C:\AdminUtil\PtDemographicQuickPrint\TxtToPDF.exe.txt";$TempFileForPrint_PathAndNamePDF&'; "C:\AdminUtil\PtDemographicQuickPrint\TxtToPDF.exe"; "C:\AdminUtil\PtDemographicQuickPrint\QuickPrintUserInterface-added hoverbuttons.au3"' ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed Global $s_eMail_CcAddress = @UserName & "@sunstarems.com"; jpennington@sunstarems.com; rsmith@sunstarems.com";"" ;"jpennington@sunstarems.com" ; address for cc - leave blank (= "") if not needed ; @UserName & "@sunstarems.com; edtemp1@tampabay.rr.com" Global $s_eMail_BccAddress = "" ; address for bcc - leave blank if not needed Global $s_eMail_Importance = "Normal" ; Send message priority: "High", "Normal", "Low" Global $s_eMail_Username = "ewilsonatsunstarems" ; username for the account used from where the mail gets sent - REQUIRED Global $s_eMail_Password = "!Password1" ; password for the account used from where the mail gets sent - REQUIRED Global $i_eMail_IPPort = 465 ; port used for sending the mail Global $i_eMail_ssl = 1 ; enables/disables secure socket layer sending - put to 1 if using httpS ;================ eMail Script ================== ;Let's reset the eMail body. $s_eMail_Body = "Ed," & @CRLF & _ "Just now, " & @UserName & " sent a test email from " & @ComputerName & " with a reason of: " & @CRLF & _ @TAB & "'Just testing.'" & @CRLF & @CRLF Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($s_eMail_SmtpServer, $s_eMail_FromName, $s_eMail_FromAddress, $s_eMail_ToAddress, $s_eMail_Subject, $s_eMail_Body, $s_eMail_AttachFiles, $s_eMail_CcAddress, $s_eMail_BccAddress, $s_eMail_Importance, $s_eMail_Username, $s_eMail_Password, $i_eMail_IPPort, $i_eMail_ssl) If @error Then ConsoleWrite("Error sending email message. " & "Error code:" & @error & " Description:" & $rc) MsgBox(0 + 16 + 262144, "Error sending email message", "Error code:" & @error & " Description:" & $rc) Else ConsoleWrite("Successfully sent email message.") EndIf ;============ end eMail Script ================== ;email function from AutoIt forums 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 = "", $i_eMail_IPPort = 25, $i_eMail_ssl = 0) Local $objEmail = ObjCreate("CDO.Message") $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($as_Body, "<") And StringInStr($as_Body, ">") Then $objEmail.HTMLBody = $as_Body Else $objEmail.Textbody = $as_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]) ;~ConsoleWrite('@@ Debug : $S_Files2Attach[$x] = ' & $S_Files2Attach[$x] & @LF & '>Error code: ' & @error & @LF) ;### Debug Console If FileExists($S_Files2Attach[$x]) Then ConsoleWrite('+> File attachment added: ' & $S_Files2Attach[$x] & @LF) $objEmail.AddAttachment($S_Files2Attach[$x]) Else ConsoleWrite('!> File not found to attach: ' & $S_Files2Attach[$x] & @LF) SetError(1) Return 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 If Number($i_eMail_IPPort) = 0 Then $i_eMail_IPPort = 25 $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $i_eMail_IPPort ;Authenticated SMTP 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 $i_eMail_ssl Then $objEmail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True EndIf ;Update settings $objEmail.Configuration.Fields.Update ; Set Email Importance Switch $s_Importance Case "High" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "High" Case "Normal" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Normal" Case "Low" $objEmail.Fields.Item("urn:schemas:mailheader:Importance") = "Low" EndSwitch $objEmail.Fields.Update ; Sent the Message $objEmail.Send If @error Then SetError(2) Return $oMyRet[1] EndIf $objEmail = "" EndFunc ;==>_INetSmtpMailCom