Jump to content

Smtp Mailer That Supports Html And Attachments.


Recommended Posts

Just now, Jos said:

No idea, this UDF is using the standard CDO COM object, so you could try searching for this whether it can be set.

Jos

Thanks Jos.

Some mail servers especially yandex blocks messages that has no usual Client ID. That's why i'm asking for .I'll dig into it. Thanks anyways and Keep Up.

Link to post
Share on other sites
  • 5 months later...
  • Replies 758
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Popular Posts

; ;################################## ; Include ;################################## #Include<file.au3> ;################################## ; Variables ;#

Agree, but first needs to be properly tested to see if everything keeps working and I haven't done that yet.  So ...  input/feedback is welcome before doing so!   My preference is to do this wi

$Body = "one" & @CRLF & "two" & @CRLF & "three" ..... ..... $Body = StringReplace($Body,@CRLF,'<br>') ;~ And now you can send your body message....  

Posted Images

Hi.

I'm trying to use your code, but it fails regardless the parameters I set.

Quote

### COM Error !  Number: 800401F3   ScriptLine: 38   Description:
### COM Error !  Number: 000000A9   ScriptLine: 39   Description:
### COM Error !  Number: 000000A9   ScriptLine: 40   Description:
### COM Error !  Number: 000000A9   ScriptLine: 43   Description:
### COM Error !  Number: 000000A9   ScriptLine: 44   Description:
### COM Error !  Number: 000000A9   ScriptLine: 45   Description:
### COM Error !  Number: 000000A9   ScriptLine: 49   Description:
### COM Error !  Number: 000000A9   ScriptLine: 66   Description:
### COM Error !  Number: 000000A9   ScriptLine: 67   Description:
### COM Error !  Number: 000000A9   ScriptLine: 69   Description:
### COM Error !  Number: 000000A9   ScriptLine: 72   Description:
### COM Error !  Number: 000000A9   ScriptLine: 73   Description:
### COM Error !  Number: 000000A9   ScriptLine: 74   Description:
### COM Error !  Number: 000000A9   ScriptLine: 80   Description:
### COM Error !  Number: 000000A9   ScriptLine: 86   Description:
### COM Error !  Number: 000000A9   ScriptLine: 90   Description:
### COM Error !  Number: 000000A9   ScriptLine: 92   Description:

It terminates with a msgbox: Error code:2 Description:

 

What is wrong with it? It seems every line with $objEmail related had failed. I think that it can't create that object, but why?

Link to post
Share on other sites
  • 4 months later...

Hi, 

Thanks a lot for the code!  

I have a question though. I'd like to send an email from my enterprise gmail account but when filling required information (username, password, addresses, etc..) I have this error message:

---------------------------
Error sending message
---------------------------
Error code:2  Description:The message could not be sent to the SMTP server. The transport error code was 0x800ccc60. The server response was * OK Gimap ready for requests from 77.203.211.214 hb3mb186828942wjd
---------------------------
OK   
---------------------------

Indeed, to connect to my pro mailbox, I have to connect to my SSO first.

The email sending is working perfectly if I use  my personal gmail account... 

Any clue on how to achieve that for my pro account? Is it at least possible?

Thanks :)

~~~ Doom Shall Never Die, Only The Players ~~~

Link to post
Share on other sites
40 minutes ago, 31290 said:

Hi, 

Thanks a lot for the code!  

I have a question though. I'd like to send an email from my enterprise gmail account but when filling required information (username, password, addresses, etc..) I have this error message:

---------------------------
Error sending message
---------------------------
Error code:2  Description:The message could not be sent to the SMTP server. The transport error code was 0x800ccc60. The server response was * OK Gimap ready for requests from 77.203.211.214 hb3mb186828942wjd
---------------------------
OK   
---------------------------

Indeed, to connect to my pro mailbox, I have to connect to my SSO first.

The email sending is working perfectly if I use  my personal gmail account... 

Any clue on how to achieve that for my pro account? Is it at least possible?

Thanks :)

Does pro Google mail use the same SMTP server as personal google?  I would try using this handy little command line tool to see if you are able to send mail that way.  Try (from command line):
CMail -from:<Enterpriseemail>:"<Your name>" -to:<Email address of recipient> -subject:"<Subject>" -body:"<Some test text>" -host:<username for enterprise login>:<Password for enterprise login>@<FQDN for smtp server used>:<port number> -starttls -requiretls -d

The text between the <> is what you fill in.  The "-d" switch will output debugging information.  You also might find this useful:
https://support.google.com/a/answer/176600?hl=en

 

Link to post
Share on other sites

MattHiggs, thanks for your input.

In fact, this is working when $Username is set to my pro email address (not my SSO username) and I have to lower the "Security Checkup" within my pro email settings.

FYI, yes, Pro Google Mail uses the same SMTP server and the same ports. 

So, no need to degub anything but thanks again :)

~~~ Doom Shall Never Die, Only The Players ~~~

Link to post
Share on other sites
19 hours ago, 31290 said:

MattHiggs, thanks for your input.

In fact, this is working when $Username is set to my pro email address (not my SSO username) and I have to lower the "Security Checkup" within my pro email settings.

FYI, yes, Pro Google Mail uses the same SMTP server and the same ports. 

So, no need to degub anything but thanks again :)

Hey man.  Whatever works, right?

Link to post
Share on other sites
On 28/03/2006 at 9:17 PM, Jos said:

 

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

Hello everybody,

I just had a problem when send attachment a database file. The file was received With  content-transfer-encoding = "quoted-printable" and corrupted database

After some reading for CDO.Message Finlay I added:

$objEmail.Attachments(1).Fields.Item("urn:schemas:mailheader:content-disposition") = "attachment"
    $objEmail.Attachments(1).Fields.Item("urn:schemas:mailheader:content-transfer-encoding") = "base64"
    $objEmail.Attachments(1).Fields.Update

"

Thats help to send attachment without corrupt.


   

Link to post
Share on other sites
  • 8 months later...
On 3/29/2006 at 1:47 AM, Jos said:

 

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

>"\\Main\E\Vinit\AutoIt3\SciTE\AutoIt3Wrapper\AutoIt3Wrapper.exe" /run /prod /ErrorStdOut /in "D:\Desktop\smtp.au3" /UserParams    
+>19:02:52 Starting AutoIt3Wrapper v.14.801.2025.0 SciTE v.3.4.4.0   Keyboard:00000409  OS:WIN_7/Service Pack 1  CPU:X64 OS:X86    Environment(Language:0409)
+>         SciTEDir => \\Main\E\Vinit\AutoIt3\SciTE   UserDir => \\Main\E\Vinit\AutoIt3\SciTE\AutoIt3Wrapper
>Running AU3Check (3.3.12.0)  from:\\Main\E\Vinit\AutoIt3  input:D:\Desktop\smtp.au3
"D:\Desktop\smtp.au3"(41,12) : error: missing separator character before keyword.
    $objEmail.To
    ~~~~~~~~~~^
D:\Desktop\smtp.au3 - 1 error(s), 0 warning(s)
!>19:02:53 AU3Check ended. Press F4 to jump to next error.rc:2
+>19:02:53 AutoIt3Wrapper Finished.
>Exit code: 2    Time: 0.8591

 

Link to post
Share on other sites
  • Developers

You are only posting my original posted code and your error message without any question. Is there one?
If you need help with the error you will have to post your version of the script, not mine! ;)

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 post
Share on other sites
7 minutes ago, Jos said:

You are only posting my original posted code and your error message without any question. Is there one?
If you need help with the error you will have to post your version of the script, not mine! ;)

Jos

Updated Autoit version and got it resolved

thanks and sorry for posting wrongly

Link to post
Share on other sites
16 minutes ago, Jos said:

You are only posting my original posted code and your error message without any question. Is there one?
If you need help with the error you will have to post your version of the script, not mine! ;)

Jos

 

i was using ur script only just changed credentials so just quoted ur post

and error seems to be with au3check old version that i was using now fixed

I was Searching and found this thread and my question was duplicate to this one so ...

 

Link to post
Share on other sites
  • 1 month later...
  • 2 months later...
  • Developers

Something like? :  :) 

$Body = "computername is " & @computername & "<br>username is " & @username

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 post
Share on other sites
11 hours ago, Jos said:

Something like? :  :) 

$Body = "computername is " & @computername & "<br>username is " & @username

Jos

Hey Jos ,

ive already done this in the UDF:

$objEmail.Subject = $s_Subject & @ComputerName

and

$objEmail.Textbody = $as_Body & @CRLF & @UserName

This adds always at the end of the message / subject the computername and username. But thanks for your answer I think that might work too. :)

 

Link to post
Share on other sites

Hi

I have a question for you mr Jos. 

I compiled ur script as mailer.exe and filled it with my information. My main goal is sending  a txt file. It works if i run the compiled file. I recieve the email with attachment. 

My problem occurs when i try to run the mailer. Exe file from my own script like this run("mailer. Exe"). It seems to work as it sends the mail and i recieve it but there is no attachment. 

My script is a long loop and the run("mailer. Exe") is positioned in the beginning of the loop and it executes about ever 10minutes.

So my question would be if you know why the file attachment is missing? 

Link to post
Share on other sites
  • Developers
7 minutes ago, Zen14 said:

My question would be if you know why the file attachment is missing? 

You have an mistake in your script, likely something with the workdir, but without showing it, there isn't much we can do.

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 post
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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...