Developers Popular Post Jos Posted March 28, 2006 Developers Popular Post Posted March 28, 2006 (edited) expandcollapse popup; ;################################## ; Include ;################################## #include <file.au3> ;################################## ; Variables ;################################## $SmtpServer = "MailServer" ; address for the smtp-server to use - REQUIRED $FromName = "Name" ; name from who the email was sent $FromAddress = "your@Email.Address.com" ; address from where the mail should come $ToAddress = "your@Email.Address.com" ; destination address of the email - REQUIRED $Subject = "Userinfo" ; subject from the email - can be anything you want it to be $Body = "" ; the messagebody from the mail - can be left blank but then you get a blank mail ; example html body with inline images. file can be quoted or unquoted, ; but the format ##image#your-filename.jpg## is fixed: ;$as_Body = "<body>E-mail with 2 images inline:<br>" & _ ; "first image: ##image#'C:\path-to-Picture\image1.png'##" & _ ; "second image: ##image#C:\path-to-Picture\image1.png##" & _ ; "<br></body>" ; $AttachFiles = "" ; the file(s) you want to attach seperated with a ; (Semicolon) - leave blank if not needed $CcAddress = "CCadress1@test.com" ; address for cc - leave blank if not needed $BccAddress = "BCCadress1@test.com" ; address for bcc - leave blank if not needed $Importance = "Normal" ; Send message priority: "High", "Normal", "Low" $Username = "******" ; username for the account used from where the mail gets sent - REQUIRED $Password = "********" ; password for the account used from where the mail gets sent - REQUIRED $IPPort = 25 ; port used for sending the mail $ssl = 0 ; enables/disables secure socket layer sending - put to 1 if using httpS $tls = 0 ; enables/disables TLS when required ;~ $SmtpServer = "smtp.gmail.com" ; GMAIL address for the smtp-server to use - REQUIRED ;~ $IPPort=465 ; GMAIL port used for sending the mail ;~ $ssl=1 ; GMAIL enables/disables secure socket layer sending - put to 1 if using httpS ;~ $SmtpServer = "smtp.office365.com" ; O365 address for the smtp-server to use - REQUIRED ;~ $IPPort=25 ; O365 port used for sending the mail ;~ $ssl=1 ; O365 enables/disables secure socket layer sending - put to 1 if using httpS ;~ SmtpServer = "smtp.mail.yahoo.com" ; Yahoo address for the smtp-server to use - REQUIRED ;~ $IPPort = 465 ; Yahoo port used for sending the mail ;~ $ssl = 1 ; Yahoo enables/disables secure socket layer sending - put to 1 if using httpS ;################################## ; Script ;################################## Global $oMyRet[2] Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc") $rc = _INetSmtpMailCom($SmtpServer, $FromName, $FromAddress, $ToAddress, $Subject, $Body, $AttachFiles, $CcAddress, $BccAddress, $Importance, $Username, $Password, $IPPort, $ssl, $tls) If @error Then MsgBox(0, "Error sending message", "Error code:" & @error & " Description:" & $rc) EndIf ; ; The UDF 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, $tls = 0) Local $objEmail = ObjCreate("CDO.Message") ; convert the Fromname to UTF-8 basex64 to allow for UTF characters in the name If $s_FromName <> "" Then $s_FromName = "=?utf-8?B?" & _Base64Encode(BinaryToString(StringToBinary($s_FromName, 4), 1)) & '?=' $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 ; add embedded images when defined Local $aImages = 0, $iImgCnt = 0 $aImages = StringRegExp($as_Body, "##image#['""]?([^#'""]*)['""]?##", $STR_REGEXPARRAYGLOBALMATCH) $iImgCnt += 1 For $i = 0 To UBound($aImages) - 1 $iImgCnt += 1 $fileext = StringRegExpReplace($aImages[$i], ".*(\.+.*)", "$1") $as_Body = StringRegExpReplace($as_Body, "(##image#['""]?([^#'""]*)['""]?##)", "<img src=" & $iImgCnt & $fileext & ">", 1) $objBP = $objEmail.AddRelatedBodyPart($aImages[$i], $iImgCnt & $fileext, 1) $objBP.Fields.Item("urn:schemas:mailheader:Content-ID") = "<" & $iImgCnt & $fileext & ">" $objBP.Fields.Update ConsoleWrite('+> Image placed inline: ' & $aImages[$i] & @LF) Next $objEmail.HTMLBody = $as_Body $objEmail.HTMLBodyPart.CharSet = "UTF-8" Else $objEmail.Textbody = $as_Body & @CRLF $objEmail.TextBodyPart.CharSet = "UTF-8" 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 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($IPPort) = 0 Then $IPPort = 25 $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = $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 ; Set security params If $ssl Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True If $tls Then $objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendtls") = True ;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 ; ; ; Com Error Handler 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 ; Base64 UDF made by Trancexx https://www.autoitscript.com/forum/topic/84133-winhttp-functions/?do=findComment&comment=1260746 Func _Base64Encode($vInput) Local Const $CRYPT_STRING_BASE64 = 0x00000001 Local Const $CRYPT_STRING_NOCRLF = 0x40000000 $vInput = Binary($vInput) Local $tInput = DllStructCreate("byte[" & BinaryLen($vInput) & "]") DllStructSetData($tInput, 1, $vInput) Local $aCall = DllCall("Crypt32.dll", "bool", "CryptBinaryToStringA", _ "struct*", $tInput, _ "dword", DllStructGetSize($tInput), _ "dword", $CRYPT_STRING_BASE64 + $CRYPT_STRING_NOCRLF , _ "ptr", 0, _ "dword*", 0) If @error Or Not $aCall[0] Then Return SetError(1, 0, "") ; error calculating the length of the needed buffer Local $tOut = DllStructCreate("char[" & $aCall[5] & "]") $aCall = DllCall("Crypt32.dll", "int", "CryptBinaryToStringA", _ "struct*", $tInput, _ "dword", DllStructGetSize($tInput), _ "dword", $CRYPT_STRING_BASE64 + $CRYPT_STRING_NOCRLF, _ "struct*", $tOut, _ "dword*", DllStructGetSize($tOut)) If @error Or Not $aCall[0] Then Return SetError(2, 0, ""); error encoding Return DllStructGetData($tOut, 1) EndFunc Edit: Fixed Bcc ... Edit: Added support for different port and SLL which are used by GMail (Port 465) Edit: Added Importance support (10/2008) Edit: Added $TLS option (07/2020) Edit: Added inline Images option in an HTML body (12/2024) Some interesting Info from the thread: On 11/8/2020 at 3:03 AM, Zedna said: Adding a MailHeader: $objEmail.Fields("urn:schemas:mailheader:x-mailer") = "My application Name or whatever else" and here is the way how to set "code page" (here Czech) : this is important when you have chars with diacritics (special non-english letters) in your email $objEmail.BodyPart.ContentTransferEncoding = "8bit" $objEmail.BodyPart.CharSet = "windows-1250"  Edited December 11 by Jos XuxinhaKill, t0nZ, oapjr and 25 others 23 5 SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past.Â
rakudave Posted March 28, 2006 Posted March 28, 2006 nicenicenice!!!! Pangaea Ruler new, UDF: _GUICtrlCreateContainer(), Pangaea Desktops, Pangaea Notepad, SuDoku, UDF: Table
Mosquitos Posted March 29, 2006 Posted March 29, 2006 Works very good; Thanks I tested with exe,doc,txt and au3 files and it works. I changed this in the script: $DefaultSmtpServer = RegRead("HKCU\Software\Microsoft\Internet Account Manager\Accounts\00000001", "SMTP Server") $rc = _INetSmtpMailCom($DefaultSmtpServer , "Your Name", "your@Email.Address.com", "CCadress1@test.com;CCadress2@test.com", "Test Subject", "Test <b>Body</b>", "test.au3;test3.au3") Sapiente vince, rex, noli vincere ferro!
slipperylobster Posted March 30, 2006 Posted March 30, 2006 i use ypops and enter my server as 127.0.0.1 (localhost) this usually works in my other programs. I get a failure to login error after AUTH Login is sent to me. Any ideas? Ypops uses localhost to access yahoo mail accts. The error reads: error code 2: message could not be sent to the smtp server. the transport error code was 0x80040217 thanks.
Developers Jos Posted March 30, 2006 Author Developers Posted March 30, 2006 i use ypops and enter my server as 127.0.0.1 (localhost) this usually works in my other programs. I get a failure to login error after AUTH Login is sent to me. Any ideas? Ypops uses localhost to access yahoo mail accts.The error reads: error code 2: message could not be sent to the smtp server. the transport error code was 0x80040217 thanks. I don't know if a proxy program will work with this COM object... you will have to do some reseach on it.. SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past.Â
lte5000 Posted April 2, 2006 Posted April 2, 2006 (edited) Com error:80020009 Error sending message, error code:2 Description:The message could not be sent to the SMTP server. The transport error code was 0x800ccc61. The server response was 560 See http://pobox.com/~djb/docs/smtplf.html. I think maybe you should change $objEmail.Textbody = $as_Body & @LF to $objEmail.Textbody = $as_Body & @CRLF Thanks for the UDF. Edited April 2, 2006 by lte5000
Developers Jos Posted April 2, 2006 Author Developers Posted April 2, 2006 I think maybe you should change $objEmail.Textbody = $as_Body & @LF to $objEmail.Textbody = $as_Body & @CRLF Thanks for the UDF. I haven't had problems yet but have updated the original post with UDF. SciTE4AutoIt3 Full installer Download page  - Beta files    Read before posting   How to post scriptsource   Forum etiquette Forum Rules  Live for the present, Dream of the future, Learn from the past.Â
mille Posted April 12, 2006 Posted April 12, 2006 Hi,Error compile at :Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")and $objEmail = ObjCreate("CDO.Message")Iam using v3.1.1, why?? help me please!!THanks so much.
Mosquitos Posted April 12, 2006 Posted April 12, 2006 Hi,Error compile at :and Iam using v3.1.1, why?? help me please!!THanks so much. You need the beta Beta Sapiente vince, rex, noli vincere ferro!
nfwu Posted April 12, 2006 Posted April 12, 2006 (edited) Beta is required... Links:http://www.autoitscript.com/autoit3/files/beta/autoit/#) Edited April 12, 2006 by nfwu TwitterOut of date stuff:Scripts: Sudoku Solver | Webserver | 3D library (Pure AutoIt) | Wood's GadgetsUDFs: _WoodUniqueID() | _DialogEditIni() | _Console*() | _GetIPConfigData() | _URLEncode/Decode()
mille Posted April 12, 2006 Posted April 12, 2006 hi, everyoneThanks for your repliesWhen run my scipt it maybe error at:Error code:1 Description:0THis is my codeGlobal $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")$rc = _INetSmtpMailCom("smtp.mail.yahoo.com" , "Tran Duc", "tranducmille@yahoo.com", "", "Test Subject", "Test <b>Body</b>", "test.au3;test3.au3")Is there any problems about my code?Thanks so much.
samtree Posted April 14, 2006 Posted April 14, 2006 I LOVE YOU!!!I have been trying to do this for SOO long!!!
mille Posted April 17, 2006 Posted April 17, 2006 HI every people!Please, Could you help me for send mail, it incorrect with my account, yahoo smtp... Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")$rc = _INetSmtpMailCom("smtp.mail.yahoo.com" , "Tran Duc", "tranducmille@yahoo.com", "", "Test Subject", "Test <b>Body</b>", "test.au3;test3.au3")Thanks so much!
kmps Posted April 17, 2006 Posted April 17, 2006 this script is great,I had sent email with my SOHU mail server.thank you very very much!
Zedna Posted April 17, 2006 Posted April 17, 2006 I'm using CDO.Message for sending SMTP mails on WINXP too, thank you JdeB for that idea I want only say here for others: It's not working on WIN98 there isn't CDO.Message object/DLL. Resources UDF Â ResourcesEx UDF Â AutoIt Forum Search
dnsi Posted April 19, 2006 Posted April 19, 2006 can you make it like a lib? My Programs:Flip-Flop File Encryption SysyemMULTIPLAYER-SOCKETSERVERHide An Archive In A Picture
VernV3 Posted April 21, 2006 Posted April 21, 2006 Hi, good job.You might want to change the following: If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.Cc = $s_BccAddressto If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress If $s_BccAddress <> "" Then $objEmail.BCc = $s_BccAddressAlso, here are a couple of links to the MSDN site for further research on the CDO.Message object for anyone interested:IMessage Interfacehttp://msdn.microsoft.com/library/default....e_interface.aspMessage CoClasshttp://msdn.microsoft.com/library/default....age_coclass.aspCDO: Part Ihttp://msdn.microsoft.com/library/default....ml/cDOpart1.asp Vern
Misha Posted May 20, 2006 Posted May 20, 2006 Hi guys when I tried to use the code I had error $ObjEmail.Send $ObjEmail.Send^ERROR Error: The requested action with this object has failed. PS.Sorry to rise up all threads.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now