Developers Popular Post Jos Posted March 28, 2006 Developers Popular Post Share 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 $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") $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($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 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 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 May 22 by Jos danish_draj, Wombat, mattsk42 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. Link to comment Share on other sites More sharing options...
rakudave Posted March 28, 2006 Share Posted March 28, 2006 nicenicenice!!!! Pangaea Ruler new, UDF: _GUICtrlCreateContainer(), Pangaea Desktops, Pangaea Notepad, SuDoku, UDF: Table Link to comment Share on other sites More sharing options...
Mosquitos Posted March 29, 2006 Share 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! Link to comment Share on other sites More sharing options...
slipperylobster Posted March 30, 2006 Share 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. Link to comment Share on other sites More sharing options...
gcriaco Posted March 30, 2006 Share Posted March 30, 2006 Works very fine. Thanks a lot Link to comment Share on other sites More sharing options...
Developers Jos Posted March 30, 2006 Author Developers Share 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. Link to comment Share on other sites More sharing options...
lte5000 Posted April 2, 2006 Share 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 Link to comment Share on other sites More sharing options...
Developers Jos Posted April 2, 2006 Author Developers Share 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. Link to comment Share on other sites More sharing options...
mille Posted April 12, 2006 Share 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. Link to comment Share on other sites More sharing options...
Mosquitos Posted April 12, 2006 Share 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! Link to comment Share on other sites More sharing options...
nfwu Posted April 12, 2006 Share 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() Link to comment Share on other sites More sharing options...
mille Posted April 12, 2006 Share 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. Link to comment Share on other sites More sharing options...
samtree Posted April 14, 2006 Share Posted April 14, 2006 I LOVE YOU!!!I have been trying to do this for SOO long!!! Link to comment Share on other sites More sharing options...
mille Posted April 17, 2006 Share 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! Link to comment Share on other sites More sharing options...
kmps Posted April 17, 2006 Share Posted April 17, 2006 this script is great,I had sent email with my SOHU mail server.thank you very very much! Link to comment Share on other sites More sharing options...
Zedna Posted April 17, 2006 Share 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 Link to comment Share on other sites More sharing options...
poisonkiller Posted April 18, 2006 Share Posted April 18, 2006 What is hotmail SMPT address? Link to comment Share on other sites More sharing options...
dnsi Posted April 19, 2006 Share Posted April 19, 2006 can you make it like a lib? My Programs:Flip-Flop File Encryption SysyemMULTIPLAYER-SOCKETSERVERHide An Archive In A Picture Link to comment Share on other sites More sharing options...
VernV3 Posted April 21, 2006 Share 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 Link to comment Share on other sites More sharing options...
Misha Posted May 20, 2006 Share 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. Link to comment Share on other sites More sharing options...
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