Jump to content

This site uses cookies. By continuing to browse the site you are agreeing to our use of cookies. Find out more here. X
X


Photo

Smtp Mailer That Supports Html And Attachments.


  • Please log in to reply
608 replies to this topic

#1 Jos

Jos

    ...

  • Developers
  • 23,289 posts

Posted 28 March 2006 - 08:17 PM

*
POPULAR

AutoIt         
; ;################################## ; 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 ;~ $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 : $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     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)


Edited by Jos, 11 May 2013 - 11:55 AM.

  • mLipok, jaberwacky, XuxinhaKill and 5 others like this

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)








#2 rakudave

rakudave

    Polymath

  • Active Members
  • PipPipPipPip
  • 245 posts

Posted 28 March 2006 - 09:37 PM

:) nicenicenice!!!! :mellow:

#3 Mosquitos

Mosquitos

    Prodigy

  • Active Members
  • PipPipPip
  • 174 posts

Posted 29 March 2006 - 10:59 AM

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!

#4 slipperylobster

slipperylobster

    Adventurer

  • Active Members
  • PipPip
  • 139 posts

Posted 30 March 2006 - 12: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. :)

#5 gcriaco

gcriaco

    Polymath

  • Active Members
  • PipPipPipPip
  • 206 posts

Posted 30 March 2006 - 03:27 PM

Works very fine.
Thanks a lot

#6 Jos

Jos

    ...

  • Developers
  • 23,289 posts

Posted 30 March 2006 - 05:04 PM

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

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#7 lte5000

lte5000

    Adventurer

  • Active Members
  • PipPip
  • 110 posts

Posted 02 April 2006 - 03:11 AM

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 by lte5000, 02 April 2006 - 03:11 AM.


#8 Jos

Jos

    ...

  • Developers
  • 23,289 posts

Posted 02 April 2006 - 06:31 PM

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. :)

Visit the SciTE4AutoIt3 Download page for the latest versions                                                                 Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)


#9 mille

mille

    Seeker

  • New Members
  • 3 posts

Posted 12 April 2006 - 08:48 AM

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.

#10 Mosquitos

Mosquitos

    Prodigy

  • Active Members
  • PipPipPip
  • 174 posts

Posted 12 April 2006 - 08:52 AM

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!

#11 nfwu

nfwu

    I'm not active on these forums

  • Active Members
  • PipPipPipPipPipPip
  • 1,234 posts

Posted 12 April 2006 - 08:53 AM

Beta is required...

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

#)

Edited by nfwu, 12 April 2006 - 08:53 AM.


#12 mille

mille

    Seeker

  • New Members
  • 3 posts

Posted 12 April 2006 - 09:43 AM

hi, everyone
Thanks for your replies

When run my scipt it maybe error at:

Error code:1 Description:0

THis is my code

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.

#13 samtree

samtree

    Seeker

  • Active Members
  • 29 posts

Posted 14 April 2006 - 07:19 AM

I LOVE YOU!!!

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

#14 mille

mille

    Seeker

  • New Members
  • 3 posts

Posted 17 April 2006 - 02:38 AM

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!

#15 kmps

kmps

    Seeker

  • Active Members
  • 45 posts

Posted 17 April 2006 - 09:40 AM

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

#16 Zedna

Zedna

    AutoIt rulez!

  • MVPs
  • 8,717 posts

Posted 17 April 2006 - 01:08 PM

I'm using CDO.Message for sending SMTP mails on WINXP too, thank you JdeB for that idea :think:

I want only say here for others: It's not working on WIN98 there isn't CDO.Message object/DLL.

#17 poisonkiller

poisonkiller

    You reached -1 posts!

  • Active Members
  • PipPipPipPipPipPip
  • 535 posts

Posted 18 April 2006 - 01:58 PM

What is hotmail SMPT address?

#18 dnsi

dnsi

    Prodigy

  • Active Members
  • PipPipPip
  • 172 posts

Posted 19 April 2006 - 11:21 PM

can you make it like a lib?

#19 VernV3

VernV3

    Seeker

  • New Members
  • 9 posts

Posted 21 April 2006 - 03: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
  • header127 likes this
Vern

#20 Misha

Misha

    Adventurer

  • Active Members
  • PipPip
  • 100 posts

Posted 20 May 2006 - 08: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 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users