Jump to content

Smtp Mailer That Supports Html And Attachments.


Jos
 Share

Recommended Posts

  • Developers

After adding the portion mentioned above after email submission i get

Line-1: Error Variable must be of type object

Donace, we are good at this forum but haven't reached that state of clarevoyancy yet. ;)

Try using the example from this first page and adapt that with your GMAIL information to see if it works for you.

by the way: the gmail server is "smtp.gmail.com" ?

When it doesn't work then post it here for us to check it out (without showing your password ofcourse :D )

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

what your not that good yet ;)

well i entered the following and it worked fine; i then tried changing the port in valuators script from 25 to 465 but it just 'hung' and then gave the error; so im assuming its to do with valuators script; so i'll move this to his thread...thanks again

#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 = "Test"                    ; name from who the email was sent
$s_FromAddress = "email@googlemail.com";  address from where the mail should come
$s_ToAddress = "email@hotmail.co.uk" ; destination address of the email - REQUIRED
$s_Subject = "Test"              ; subject from the email - can be anything you want it to be
$as_Body = "This is a test email"                          ; 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 = "username"                  ; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
$s_Password = "password"                ; 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 = 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($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
Link to comment
Share on other sites

Here is a SMTPEmail Function that will Attach files and set Importance alond with DelvRecpt and ReadRecpt. Have taken several examples and came up with it.

#include <array.au3>


; $SendFrom = "Fred@Flintston.com"
; $strSendTo = "Fred@Flintston.com;Barney@Rubbel.com"
; $SendCC = "Fred@Flintston.com;Barney@Rubbel.com"
; $SendBcc = "Fred@Flintston.com;Barney@Rubbel.com"
; $Subject = "Subject Line"
; $BodyText = "BODYTEXT"
; $BodyType = "HTML";* HTML BodyText should be an HTML format
;                 ;* URL BodyText  Shoudlbe a URL Pointer
;                 ;* Text Body Text should be Plain Text Format
; $arrAttachment = StringSplit("C:\boot.old|C:\BRSIDS.TXT","|")
; $Importance = 2;* 1 = Normal 2 = High
; $DelvRecpt = "Fred@Flintston.com"
; $ReadRecpt = "Fred@Flintston.com"
; $SMTPServer = "SMTPServer"
; $UserID = ""
; $Pwd = ""

; $rtnCode = SendSMTPMail($SendFrom,$SendTo,$SendCC,$SendBcc,$Subject,$BodyText,$BodyType, _ 
;                  $arrAttachment,$Importance,$DelvRecpt,$ReadRecpt,$SMTPServer,$UserID,$Pwd)


Func SendSMTPMail($strSendFrom, $strSendTo, $SendCC, $SendBcc, $Subject, _
                  $BodyText, $BodyType, $arrAttachment, $Importance, _
                  $DelvRecpt, $ReadRecpt, $SMTPServer, $UserID, $Pwd)
    Const $cdoSendUsingPickup = 1 
    Const $cdoSendUsingPort = 2         ;* 1 = Send message using the local SMTP service pickup directory.
                                        ;* 2 = Send the message using the network (SMTP over the network),
    Const $cdoAnonymous = 0
    Const $cdoBasic = 1                 ;* 2 for NTLM, 1 for basic, 0 for none (the default)
    Const $cdoNTLM = 2                  ;* NTLM
;* Delivery Status Notifications
    Const $cdoDSNDefault = 0            ;* None
    Const $cdoDSNNever = 1              ;* None
    Const $cdoDSNFailure = 2            ;* Failure
    Const $cdoDSNSuccess = 4            ;* Success
    Const $cdoDSNDelay = 8              ;* Delay
    Const $cdoDSNSuccessFailOrDelay = 14;* Success, failure or delay    SendSMTPMail = 0 & ",Start SMTPEmail"
    Local $objMsg = ObjCreate("CDO.Message")
    Local $objConf = ObjCreate("CDO.Configuration")
    Local $objFlds = $objConf.Fields
    With $objFlds
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = $cdoSendUsingPort
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = $SMTPServer
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = $cdoBasic
    ;* Use SSL for the connection (True or False):
        .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 0
        .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = $UserID
        .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = $Pwd
        .Update()
    EndWith
    With $objMsg
        .Configuration = $objConf
        .To = $strSendTo
        .From = $strSendFrom
        .CC = $SendCC
        .BCC = $SendBcc
        .Subject = $Subject
        If StringUpper($BodyType) = "HTML" Then 
            .HTMLBody = $BodyText               ;* HTML mail
        ElseIf StringUpper($BodyType) = "URL" Then ;* URL Mail
            .CreateMHTMLBody = $BodyText
        Else
            .Textbody = $BodyText               ;* Text mail
        EndIf 
        If IsArray($arrAttachment) Then 
            For $i = 1 to $arrAttachment[0] Step 1
                If $arrAttachment[$i] <> "" Then 
                    .AddAttachment ($arrAttachment[$i])
                    If @error <> 0 Then 
                        .TextBody = .TextBody & @CRLF & @CRLF & _ 
                        "Unable to attach file " & $strAttachment & "." 
                    EndIf 
                EndIf 
            Next 
        EndIf 
       ;* set mail $Importance
        .Fields.Item("urn:schemas:httpmail:importance") = $Importance;* For Outlook Express
        If $DelvRecpt <> "" Then
            .Fields("urn:schemas:mailheader:return-receipt-to") = $DelvRecpt 
            .DSNOptions = $cdoDSNSuccessFailOrDelay
        EndIf
        If $ReadRecpt <> "" Then
            .Fields("urn:schemas:mailheader:disposition-notification-to") = $ReadRecpt
        EndIf
        .Fields.update()
        .Send()
        If @error = 0 Then
            Return 0 & ",Send Complete"
        Else
            Return @error
        EndIf
    EndWith 
EndFunc
Link to comment
Share on other sites

  • 4 weeks later...

I'm using a script where I have it calling the following function:

_INetSmtpMailCom("servername", "From me", "address@here.com", "to@there.com", "blah", "blah blah")

Whenever I run the script it sends me two emails, the first is what I have specified in the above code and the second is based on the information provided in the variables in the INetSmtpMailCom file..

How can I set it up so I only receive the one email? If I try to set the variables in the INetSmtpMailCom file to blank then it shoots off a error...

Link to comment
Share on other sites

  • Developers

I'm using a script where I have it calling the following function:

_INetSmtpMailCom("servername", "From me", "address@here.com", "to@there.com", "blah", "blah blah")

Whenever I run the script it sends me two emails, the first is what I have specified in the above code and the second is based on the information provided in the variables in the INetSmtpMailCom file..

How can I set it up so I only receive the one email? If I try to set the variables in the INetSmtpMailCom file to blank then it shoots off a error...

I don't understand how you set it up. Did you put the INetSmtpMailCom UDF in a separate file ?

If so, then what have you exactly put in it because you state it sends 2 emails so I can only assume you call the UDF 2 times.

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

Hmm, didn't see that you had replied.

What I am doing is using your SMTP mailer as a UDF. I call it with #include <Email.au3>... Then later in the script I put in _INetSmtpMailCom("servername", "From me", "address@here.com", "to@there.com", "blah", "blah blah")

If I then run the script it sends me two emails. One is with the information from the function I call in the script and the other is from the information in the UDF file. If I don't put any information in the UDF file then it errors, but still send the email from the script.

Does that make sense?

Link to comment
Share on other sites

  • Developers

Hmm, didn't see that you had replied.

What I am doing is using your SMTP mailer as a UDF. I call it with #include <Email.au3>... Then later in the script I put in _INetSmtpMailCom("servername", "From me", "address@here.com", "to@there.com", "blah", "blah blah")

If I then run the script it sends me two emails. One is with the information from the function I call in the script and the other is from the information in the UDF file. If I don't put any information in the UDF file then it errors, but still send the email from the script.

Does that make sense?

Could you provide me with a copy of your script and include file so I can have a look to see where things go wrong?

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

  • Developers

Just remove these lines from the email.au3 as you don't want them executed.. :)

$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

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

has anyone tried this out on WinXP Embedded. I am running a backup script and am trying to have the log file emailed to myself from the remote devices. I run the script on my workstation and email works fine. I try it on the WinXP Embedded and I get the following errors.

### COM Error ! Number 800401F3 Scriptline: -1 Discription

### COM Error ! Number 000000A9 Scriptline: -1 Discription (numerous times)

As soon as I take out the call to the _INetSmtpMailCom function it runs I just don't get my email.

Edited by mnchartier
Link to comment
Share on other sites

  • Developers

You need to ask yourself the question whether the Embedded windows device has the CDO object loaded which is used by this UDF.

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

Added support to set the importance of a Email to "High", "Normal" or "Low" .. see first post.

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

Trying to figure out how I would add mutiple lines of HTML. Also trying to figure out how I would embed an image. Is this possible?

How do you define this as the $as_Body variable?

<HTML>
<head>
<title>Hello World</title>
</head>
<body>
<img  src="http://server/images/HelloWorld.gif" alt="Hello World">
<font color="yellow">
 Hello World
</font>
</HTML>
Edited by joshiieeii
Link to comment
Share on other sites

  • Developers

Something like this?

$as_Body = '<HTML>' & @CRLF
$as_Body &= '<head>' & @CRLF
$as_Body &= '<title>Hello World</title>' & @CRLF
$as_Body &= '</head>' & @CRLF
$as_Body &= '<body>' & @CRLF
$as_Body &= '<img  src="http://server/images/HelloWorld.gif" alt="Hello World">' & @CRLF
$as_Body &= '<font color="yellow">' & @CRLF
$as_Body &= 'Hello World' & @CRLF
$as_Body &= '</font>' & @CRLF
$as_Body &= '</HTML>' & @CRLF

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

  • 3 weeks later...

I have the same problems like longtex and Leoj.

Many people use a Program from me which sends an Email both to themselves and to my private email adress using the 111.com smtp server (mail.111.com)

It works fine on most of the users but on some there have been problems with sending.

They get this error:

Guess what.. the ones with the Problem are having SBC as ISP.

So does anyone have updates on this problem or maybe an idea how to get that Mail sent?

The people can send normal Emails with their Emailprogramm but not with the CDO.Message Object.

There have to be a difference.

SBC, COX, and other providers block outbound mail on the DEFAULT port (25).

Use an alternate outbound port.

Link to comment
Share on other sites

  • 2 weeks later...
  • Developers

:mellow: it tried taken my html page from dream weaver to auto it and well i end up geting a blank email...

I am sure the problem lies somewhere in the beginning of your script, but when you want a more serious reply you will have to provide more information.

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