Jump to content

Smtp Mailer That Supports Html And Attachments.


Jos
 Share

Recommended Posts

  • Developers

Is there any way to add multipe CC's or BCC's to this script.

Sure, just seperate them like this:

"CCadress1@test.com;CCadress2@test.com"

Jos

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

  • 2 weeks later...

Hey man, this is driving me crazy. Do you know what I'm doing wrong? I'm using the beta.

#Include<file.au3>
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;##################################
; Include
;##################################
#Include<file.au3>
;##################################
; Variables
;##################################
$s_SmtpServer = "smtp.gmail.com"             ; address for the smtp-server to use - REQUIRED
$s_FromName = "Steve"                    ; name from who the email was sent
$s_FromAddress = "myemail@gmail.com";  address from where the mail should come
$s_ToAddress = "myotheremail@gmail.com"  ; destination address of the email - REQUIRED
$s_Subject = "TEST"               ; subject from the email - can be anything you want it to be
$as_Body = "test sbody"                         ; the messagebody from the mail - can be left blank but then you get a blank mail
$s_AttachFiles = ""                   ; the file you want to attach- leave blank if not needed
$s_CcAddress = ""     ; address for cc - leave blank if not needed
$s_BccAddress = ""  ; address for bcc - leave blank if not needed
$s_Username = "myusername"                 ; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
$s_Password = "mypass"               ; password for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
;$IPPort = 25                            ; port used for sending the mail
$ssl = 1                                 ; 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($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body, $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl)
If @error Then
    MsgBox(0, "Error sending message", "Error code:" & @error & "  Rc:" & $rc)
EndIf
;

Func _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject = "", $as_Body = "", $s_AttachFiles = "", $s_CcAddress = "", $s_BccAddress = "", $s_Username = "", $s_Password = "",$IPPort=25, $ssl=0)
    $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])
            If FileExists($S_Files2Attach[$x]) Then
                $objEmail.AddAttachment ($S_Files2Attach[$x])
            Else
                $i_Error_desciption = $i_Error_desciption & @lf & 'File not found to attach: ' & $S_Files2Attach[$x]
                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
    $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
; Sent the Message
    $objEmail.Send
    if @error then
        SetError(2)
        return $oMyRet[1]
    EndIf
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

It didnt send. I obviously changed the settings at the top to my real stuff but yeah, is the code OK for gmail?

Link to comment
Share on other sites

  • Developers

Looks fine to me.... did you get any errors in the SciTE Outputpane? (assuming you used SciTE to run it)

Edited by Jos

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

  • Developers

When you don't get a MSGBOX() it means you have @error set to 1, which in turn means there was an error and something should have been displayed.

Try changing the ConsoleWrite() to an MSGBOX() in the MyErrFunc() to see if that shows anything.

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

  • Developers

What happens when you run your posted version (with dummy info)...

I get the following error:

### COM Error !  Number: 80020009   ScriptLine: 78   Description:The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available

Pls also show your total SciTE output pane info so I can see what you are running.

Edited by Jos

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

Yea I get something similar to that.

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\Steve\Desktop\New AutoIt v3 Script.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams   
+>16:11:51 Starting AutoIt3Wrapper v.1.10.1.8   Environment(Language:0409  Keyboard:00000409  OS:WIN_XP/Service Pack 3  CPU:X86)
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3
+>16:11:51 AU3Check ended.rc:0
>Running:(3.2.12.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\Steve\Desktop\New AutoIt v3 Script.au3" 
### COM Error !  Number: 80020009   ScriptLine: 79   Description:The transport failed to connect to the server.
+>16:11:56 AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 6.020
Link to comment
Share on other sites

  • Developers

Your error is indeed different. You are sure you can connect to the server from where you are trying?

To test you could do: telnet smtp.gmail.com 465

That should open a telnet session.

Other than that I am not sure what else it could be. I do not have a GMail account and the script is working fine for me on my own providers network.

Jos

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

Yea, I tried opening a telnet session before. It just comes up blank though, no response or welcome. But do you know of any free smtp servers out there I can use? How about yahoo? Have you ever tried yahoo? I appreciate your help btw. Thanks.

Link to comment
Share on other sites

  • Developers

Yea, I tried opening a telnet session before. It just comes up blank though, no response or welcome. But do you know of any free smtp servers out there I can use? How about yahoo? Have you ever tried yahoo? I appreciate your help btw. Thanks.

The blank session sounds good. Didn't expect anything readable on a SSL connection.

Yahoo doesn't have a free to use SMTP server and you won't find many open relay SMTP servers for the simple fact that they would be mis-used by our MASS SPAMMER friends.

It still puzzels me that the mail isn't sent. are you sure it really isn't sent? did you try sending it to another email address?

Jos

Edited by Jos

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

I just tried yahoo and I got the following error messages. Any ideas?

>"C:\Program Files\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "C:\Documents and Settings\Steve\Desktop\email.au3" /autoit3dir "C:\Program Files\AutoIt3" /UserParams  
+>17:51:02 Starting AutoIt3Wrapper v.1.10.1.8   Environment(Language:0409  Keyboard:00000409  OS:WIN_XP/Service Pack 3  CPU:X86)
>Running AU3Check (1.54.13.0)  from:C:\Program Files\AutoIt3
+>17:51:02 AU3Check ended.rc:0
>Running:(3.2.12.0):C:\Program Files\AutoIt3\autoit3.exe "C:\Documents and Settings\Steve\Desktop\email.au3"    
### COM Error !  Number: 80020009   ScriptLine: 79   Description:The message could not be sent to the SMTP server. The transport error code was 0x800ccc67. The server response was 421 Cannot connect to SMTP server 69.147.102.58 (69.147.102.58:25), connect error 10060
Error sending message Error code:2  Rc:The message could not be sent to the SMTP server. The transport error code was 0x800ccc67. The server response was 421 Cannot connect to SMTP server 69.147.102.58 (69.147.102.58:25), connect error 10060+>17:51:24 AutoIT3.exe ended.rc:0
>Exit code: 0   Time: 22.776
Link to comment
Share on other sites

Thanks a lot. It was working just fine but now I get this error:

Error code:2 Rc:The message could not be sent to the SMTP server. The transport error code was 0x80040217. The server response was not available

Help :)

EDIT: (gmail) and i tried telnet too and works

Edited by Aassdd
Link to comment
Share on other sites

  • Developers

Yea, I tried opening a telnet session before. It just comes up blank though, no response or welcome. But do you know of any free smtp servers out there I can use? How about yahoo? Have you ever tried yahoo? I appreciate your help btw. Thanks.

Just created myself an gmail account and used your exact posted script, changed it to my account info and ran it.

It worked just fine. Do you have any firewallsoftware blocking things ?

Jos

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...