Jump to content

Smtp Mailer That Supports Html And Attachments.


Jos
 Share

Recommended Posts

I get this error in the msgbox:

Error code:2 Rc:The message could not be sent to the SMTP server. The transport error code was 0x800ccc6f. The server response was 554 5.7.1ussp-sefw-2.COMPANYNAME.com Connection not authorized

and this in SciTe

### COM Error ! Number: 80020009 ScriptLine: 79 Description:The message could not be sent to the SMTP server. The transport error code was 0x800ccc6f. The server response was 554 5.7.1 ussp-sefw-2.COMPANYNAME.com Connection not authorized

With this code beta or prod

#Include<file.au3>
Global $oMyError = ObjEvent("AutoIt.Error", "MyErrFunc")
;##################################
; Include
;##################################
#Include<file.au3>
;##################################
; Variables
;##################################
$s_SmtpServer = "smtp.mail.yahoo.com"              ; address for the smtp-server to use - REQUIRED
$s_FromName = "myaddress@yahoo.com"                      ; name from who the email was sent
$s_FromAddress = "myaddress@yahoo.com" ;  address from where the mail should come
$s_ToAddress = "testsendtoaddy@gmail.com"   ; destination address of the email - REQUIRED
$s_Subject = "Userinfo"                   ; subject from the email - can be anything you want it to be
$as_Body = "Testing"                             ; 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 = "myaddress@yahoo.com"                    ; 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
Edited by danwilli
Link to comment
Share on other sites

  • 1 month later...

Hi,

I can send unauthenticated e-mail fine with this script, however if I try and authenticate to the SMTP server I get the following error in the console

>Running:(3.2.4.9):C:\Program Files\AutoIt3\autoit3.exe "D:\Temp\Shadow\INetSmtpMailCom.au3"    
D:\Temp\Shadow\INetSmtpMailCom.au3 (88) : ==> The requested action with this object has failed.: 
$objEmail.Send 
$objEmail.Send^ ERROR
->14:50:56 AutoIT3.exe ended.rc:1
+>14:50:57 AutoIt3Wrapper Finished

Here's the reporting from the error handler

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

Answer

OK, it turns out that I goofed by using the wrong password. However having acknowledged that, ideally the script should not crash because of garbage input ... although I guess that is debatable ... crap input leads to crap output.

Cheers

VW

Edited by VeeDub
Link to comment
Share on other sites

  • 4 weeks later...

i have created a small script, which should search in a main folder for subfolders

and search the subfolders for files which should be attached to the mail. the mail

address could be found in a file name.

when i run the script it works but i get an access denied error, i have also

created a loop but i can't find where it is.

### COM Error ! Number: 80020009 ScriptLine: 85 Description:Access denied

Error code:2 Rc:Access denied

ScriptLine 85: $objEmail.AddAttachment ($S_Files2Attach[$x])

i run the script with the following code:

$search1 = FileFindFirstFile("*.*")
While 1
    $s_AttachFiles =""
    $s_ToAddress=""
    $Dir_Cost = FileFindNextFile($search1)
    If $Dir_Cost ="" Then
        Exit
    EndIf
    $search2 = FileFindFirstFile($Dir_Cost & "\*.*")
    $i=1
    While $i=1
        $File_Cost = FileFindNextFile($search2)
        If $File_Cost = "" Then
            $i=0
        EndIf
        If $File_Cost <> "" Then
            If StringInStr ($File_Cost, "@") = 0 Then
                $s_AttachFiles = $s_AttachFiles & "C:\tmp\temp2\" & $Dir_Cost & "\" & $File_Cost & ";"
            EndIf
            If StringInStr ($File_Cost, "@") > 0 Then
                $s_ToAddress = $File_Cost
            EndIf
        EndIf
    WEnd
    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
WEnd
Edited by apfel
Link to comment
Share on other sites

  • Developers

What does the $s_AttachFiles variable contain when the mail is sent ?

Maybe you need to enclose all filenames with "" ?

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

the variable contains the following: c:\dir1\dir2\test.bmp;c:\dir1\dir2\test.wav;c:\dir1\dir2\test.txt;

Are the Dirs containing spaces and did you try to put the whole filenames in "" ?

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...
  • 1 month later...
  • 2 weeks later...
  • Developers

Think it will only work with an Yahoo Mail Plus account.

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

  • 4 weeks later...

Hey, this works very very very very good, but i have a question, is possible to send a mail by SPA password authentication SMTP server mail? You are working on this? Now, there are many accounts calling authentication SPA........

Thanks for your work is so useful.

Link to comment
Share on other sites

anyhelp it keeps rejecting sender adress ive tried my hotmail ,isp and my gmail in sender but still same error

cheers C.W

C.Wnew rules:1.dont use plz in a post or title use please instead2.always use help file as it is now muchly over rated3. dont think where not watching u4.please wait 24 hours after last post ot bump XD i use to make that mistake

Link to comment
Share on other sites

  • 5 months 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:

### COM Error !

Number: 80020009

ScriptLine: -1

Description:The transport failed to connect to the server.

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.

Teamspeak 3 User Viewer - Quick and functional TS3 Query script, which shows online users.Cached Screenshot Deleter - Deletes older Fraps Screenshots if they exceed a specified limit.Unresolved Topics:Intercept and modify dragdrop text behaviour in scite
Link to comment
Share on other sites

  • 2 weeks later...

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