Jump to content

Smtp Mailer


Recommended Posts

;
;##################################
; 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

I have tried Jos code (last updated May 2013 from what I can tell).

I did input my correct info for mailing (To/From).

Since I used AT&T, I went to their info and got:

SMTP Server: outbound.att.net (requires authentication)
Mail Ports: Incoming Mail Port #995: SSL Checked; Outgoing Mail Port #465: SSL Checked

I included my user name /password info as well.

I also correctly input the file I wanted to attach.  The console window says it attached.

The error code I get (and don't understand or know why) is:

### COM Error !  Number: 80020009   ScriptLine: 153   Description:The transport failed to connect to the server. Which that line in the code is : $objEmail.Send

I also get a Msg Box: The transport failed to connect to the server.

Any way I would appreciate any direction on what I am lacking in this and apologize for any duplicating of question.

Thanks

Hobbyist

 

Link to comment
Share on other sites

Thanks for the reply.

My attached code is just as it was posted on the site by you.

On my computer, in SCITE, I made the changes to what I mentioned in my post.

For instance, for the $FromAddress = "your@Email.Address.com" , I changed it to my email address. And so on and so on for the other mentioned variables.  $SmtpServer = "MailServer"  changed to outbound.att.net and the port to 465 as per AT&T info.  And the file I attached was reported on console as being attached, so I think that was right. 

Didn't change your code, just the variables per your comment sections, which were easy to follow.

 

Thanks

Hobbyist

Link to comment
Share on other sites

  • Developers

Did you change the SSL variable to 1 and set the username and password variables?

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

Yes indeed.  I originally set the username and password requirements.

Also changed the SSL variable to 1.

I'm new at this, so here is a newbie question as well.

If I change the variables (password, username, port and ssl) up in the variable section, does port and ssl get changed back here:

; 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)  ?????

or should I change it there as well. I didn't notice it there before.

I really have no idea how to trouble shoot this.

 

Link to comment
Share on other sites

Yes indeed.  I originally set the username and password requirements.

Also changed the SSL variable to 1.

I'm new at this, so here is a newbie question as well.

If I change the variables (password, username, port and ssl) up in the variable section, does port and ssl get changed back here:

; 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)  ?????

or should I change it there as well. I didn't notice it there before.

I really have no idea how to trouble shoot this.

 

Link to comment
Share on other sites

Also I went back to the AT&T site:

https://www.att.com/esupport/article.html#!/dsl-high-speed/KM1010523

I don't know the difference between: POP3 and IMAP.

Domain                           SMTP server / port 

att.net       POP3            outbound.att.net / 465

                  IMAP             smtp.mail.att.net / 465 or 587

 

(And SSL required for both)

I am guessing the error msg in my OP means not connecting to the server or something ??

 

 

Link to comment
Share on other sites

  • Developers

Correct (to your first question where to update), but that is why I asked for your version to see whether you specified all in the correct way.
My guess is you need this in the settings:

$SmtpServer = "outbound.att.net"       ; address for the smtp-server to use - REQUIRED
$FromName = "Your name"                 ; name from who the email was sent
$FromAddress = "your@att.net"           ; address from where the mail should come
$ToAddress = "your@any.email"           ; destination address of the email - REQUIRED
$Subject = "Test Email"                 ; subject from the email - can be anything you want it to be
$Body = "Test 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 = ""                         ; address for cc - leave blank if not needed
$BccAddress = ""                        ; address for bcc - leave blank if not needed
$Importance = "Normal"                  ; Send message priority: "High", "Normal", "Low"
$Username = "YourATTId@att.net"         ; username for the account used from where the mail gets sent - REQUIRED
$Password = "Password"                  ; password for the account used from where the mail gets sent - REQUIRED
$IPPort=465                             ; ATT port used for sending the mail
$ssl=1                                  ; ATT enables/disables secure socket layer sending - put to 1 if using httpS

You could also try this different smtp server:

$SmtpServer = "smtp.mail.att.net"

The error indeed point to the fact that it cannot establish an connection to the server.
Is the sending of Email working from an email client on this pc?

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

OK, I changed this >>  $SmtpServer = "smtp.mail.att.net" .

I had all the To/Fr email requirements entered, along with username/password.

Your question: Is the sending of Email working from an email client on this pc?  I am not sure I understand what you mean "email client" (sorry).  My ISP is AT&T and my email goes through it.  Yahoo and ATT have some kind of deal whereby I bring up Yahoo page but my username and sign on are for ATT or I can go to ATT.net and sign in . 

I also made sure $IPPort = 25, $ssl = 0 in the UDF is changed to 465 and 1 respectively.

Link to comment
Share on other sites

  • Developers
1 hour ago, Hobbyist said:

I am not sure I understand what you mean "email client" (sorry)

Are you using any program to read/send emails on your PC with these settings like Outlook or something and is that working? Just to establish things should be working.
So you have tried the different options and all are still failing with the same error?

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

OK, I changed this >>  $SmtpServer = "smtp.mail.att.net" .

I had all the To/Fr email requirements entered, along with username/password.

Your question: Is the sending of Email working from an email client on this pc?  I am not sure I understand what you mean "email client" (sorry).  My ISP is AT&T and my email goes through it.  Yahoo and ATT have some kind of deal whereby I bring up Yahoo page but my username and sign on are for ATT or I can go to ATT.net and sign in . 

I also made sure $IPPort = 25, $ssl = 0 in the UDF is changed to 465 and 1 respectively.

Link to comment
Share on other sites

  • Developers
Just now, Hobbyist said:

Yes, I send and rec emails on this pc using email in att.net, yahoo, gmail.

How? Which program?

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

ok, It seem I am not speaking the right language for us to communicate properly and am sorry for that.
Hopefully soon there will be someone that does.

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

No it is I who is lacking and for that I am sorry, since it takes some time.

I will do or look for anything you direct me to look for or test. 

The only emailing I know is to go to att.net, sign in and on their startup page I can select "email button" which brings up the window with To:/Fr:/Subject etc type fields and then the text body where the msg goes.  A friend showed me how to "ping" att to see if I can hit it. That was using the cmd in the "run" window. It my pc hits its. Does that help at all.

Link to comment
Share on other sites

I just tried something to check things on my end.

Used Cobian Gravity backup app which has the option to email report upon completing backup.

It works and I get a report sent.  Using port 465,  outbound.att.net, my username and password.

Is it possible my SCITE version is an issue??  

Version 3.4.1
    Mar 30 2014 21:57:28.

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