AutoIt Forums: Smtp Mailer That Supports Html And Attachments. - AutoIt Forums

Jump to content

  • (15 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

Smtp Mailer That Supports Html And Attachments. Also Secure SMTP mail (GMail) Rate Topic: ***** 10 Votes

#1 User is offline   Jos 

  • SciTE4AutoIt3 ..What else ?
  • Icon
  • Group: Developers(Dev)
  • Posts: 15,647
  • Joined: 03-December 03
  • Gender:Male
  • Location:The Netherlands

Posted 28 March 2006 - 09:17 PM

[ autoIt ]    ( 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 you want to attach- 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 ;~ $IPPort=465                          ; GMAIL port used for sending the mail ;~ $ssl=1                               ; GMAILenables/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) 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)     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(62) : $S_Files2Attach = ' & $S_Files2Attach & @LF & '>Error code: ' & @error & @LF) ;### Debug Console             If FileExists($S_Files2Attach[$x]) Then                 $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     If $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 ; ; ; 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)

This post has been edited by Jos: 07 October 2008 - 07:21 AM

0

#2 User is offline   rakudave 

  • Spammer!
  • PipPipPip
  • Group: Full Members
  • Posts: 245
  • Joined: 14-June 05
  • Location:Switzerland

Posted 28 March 2006 - 10:37 PM

:thumbsup: nicenicenice!!!! :thumbsup:
0

#3 User is offline   Mosquitos 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 171
  • Joined: 10-April 05
  • Location:Belguim

Posted 29 March 2006 - 11:59 AM

Works very good; Thanks
I tested with exe,doc,txt and au3 files and it works.

I changed this in the script:
[ code='text' ]    ( Popup )
$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")

0

#4 User is offline   slipperylobster 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 139
  • Joined: 22-July 05
  • Location:philippines (USA expat living there)

Posted 30 March 2006 - 01:33 AM

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. :'(
0

#5 User is offline   gcriaco 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 197
  • Joined: 10-April 04
  • Location:Rome, Italy

Posted 30 March 2006 - 04:27 PM

Works very fine.
Thanks a lot
0

#6 User is offline   Jos 

  • SciTE4AutoIt3 ..What else ?
  • Icon
  • Group: Developers(Dev)
  • Posts: 15,647
  • Joined: 03-December 03
  • Gender:Male
  • Location:The Netherlands

Posted 30 March 2006 - 06:04 PM

View Postslipperylobster, on Mar 30 2006, 02:33 AM, said:

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..
0

#7 User is offline   lte5000 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 110
  • Joined: 31-March 04

Posted 02 April 2006 - 04:11 AM

Quote

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

[ code='text' ]    ( Popup )
$objEmail.Textbody = $as_Body & @LF


to

[ code='text' ]    ( Popup )
$objEmail.Textbody = $as_Body & @CRLF


Thanks for the UDF.

This post has been edited by lte5000: 02 April 2006 - 04:11 AM

0

#8 User is offline   Jos 

  • SciTE4AutoIt3 ..What else ?
  • Icon
  • Group: Developers(Dev)
  • Posts: 15,647
  • Joined: 03-December 03
  • Gender:Male
  • Location:The Netherlands

Posted 02 April 2006 - 07:31 PM

View Postlte5000, on Apr 2 2006, 05:11 AM, said:

I think maybe you should change

[ code='text' ]    ( Popup )
$objEmail.Textbody = $as_Body & @LF


to

[ code='text' ]    ( Popup )
$objEmail.Textbody = $as_Body & @CRLF


Thanks for the UDF.


I haven't had problems yet but have updated the original post with UDF. :)
0

#9 User is offline   mille 

  • Newbie
  • Group: Members
  • Posts: 3
  • Joined: 12-April 06

Posted 12 April 2006 - 09:48 AM

Hi,
Error compile at :

Quote

Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
and

Quote

$objEmail = ObjCreate("CDO.Message")

Iam using v3.1.1, why?? help me please!!
THanks so much.
0

#10 User is offline   Mosquitos 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 171
  • Joined: 10-April 05
  • Location:Belguim

Posted 12 April 2006 - 09:52 AM

View Postmille, on Apr 12 2006, 10:48 AM, said:

Hi,
Error compile at :

and

Iam using v3.1.1, why?? help me please!!
THanks so much.

You need the beta Beta
0

#11 User is offline   nfwu 

  • PM / e-mail me: I'm not active on these forums
  • PipPipPipPipPipPip
  • Group: Full Members
  • Posts: 1,227
  • Joined: 31-July 05
  • Location:http://claimid.com/nfwu

Posted 12 April 2006 - 09:53 AM

Beta is required...

Links:http://www.autoitscript.com/autoit3/files/beta/autoit/

#)

This post has been edited by nfwu: 12 April 2006 - 09:53 AM

0

#12 User is offline   mille 

  • Newbie
  • Group: Members
  • Posts: 3
  • Joined: 12-April 06

Posted 12 April 2006 - 10:43 AM

hi, everyone
Thanks for your replies

When run my scipt it maybe error at:

Quote

Error code:1 Description:0
THis is my code

Quote

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")


Is there any problems about my code?
Thanks so much.
0

#13 User is offline   samtree 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 29
  • Joined: 12-August 05

Posted 14 April 2006 - 08:19 AM

I LOVE YOU!!!

I have been trying to do this for SOO long!!!
0

#14 User is offline   mille 

  • Newbie
  • Group: Members
  • Posts: 3
  • Joined: 12-April 06

Posted 17 April 2006 - 03:38 AM

HI every people!

Please, Could you help me for send mail, it incorrect with my account, yahoo smtp...

Quote

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!
0

#15 User is offline   kmps 

  • Member
  • Pip
  • Group: Full Members
  • Posts: 45
  • Joined: 21-March 06

Posted 17 April 2006 - 10:40 AM

this script is great,I had sent email with my SOHU mail server.thank you very very much!
0

#16 User is offline   Zedna 

  • AutoIt rulez!
  • Icon
  • Group: AutoIt MVPs(MVP)
  • Posts: 6,249
  • Joined: 17-June 05
  • Location:Czech republic

Posted 17 April 2006 - 02:08 PM

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.
0

#17 User is offline   poisonkiller 

  • You reached -1 posts!
  • PipPipPipPip
  • Group: Full Members
  • Posts: 521
  • Joined: 15-September 05

Posted 18 April 2006 - 02:58 PM

What is hotmail SMPT address?
0

#18 User is offline   dnsi 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 172
  • Joined: 26-March 06

Posted 20 April 2006 - 12:21 AM

can you make it like a lib?
0

#19 User is offline   VernV3 

  • Newbie
  • Group: Members
  • Posts: 9
  • Joined: 17-April 06

Posted 21 April 2006 - 04:43 PM

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_BccAddress

to

If $s_CcAddress <> "" Then $objEmail.Cc = $s_CcAddress
If $s_BccAddress <> "" Then $objEmail.BCc = $s_BccAddress


Also, here are a couple of links to the MSDN site for further research on the CDO.Message object for anyone interested:

IMessage Interface
http://msdn.microsoft.com/library/default....e_interface.asp

Message CoClass
http://msdn.microsoft.com/library/default....age_coclass.asp

CDO: Part I
http://msdn.microsoft.com/library/default....ml/cDOpart1.asp
0

#20 User is offline   Misha 

  • Advanced Member
  • PipPip
  • Group: Full Members
  • Posts: 100
  • Joined: 18-March 06

Posted 20 May 2006 - 09:57 AM

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.
0

  • (15 Pages)
  • +
  • 1
  • 2
  • 3
  • Last »
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users