kevin_amo

_INetSmtpMailCom error code:2

15 posts in this topic

#1 ·  Posted

I have searched and read all topics related to this and pretty much tried every thing, but still i get the error code:2!

#include <file.au3>

$Subject = "hi"
$Body = "it works"
$ToAddress = "toaddress@gmail"

_SendEmail($Subject, $Body, $ToAddress)

Func _SendEmail($Subject, $Body, $ToAddress)
    $SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED
    $FromName = "runME script" ; name from who the email was sent
    $FromAddress = "myaddress@gmail.com" ; address from where the mail should come
    $ToAddress = $ToAddress ; destination address of the email - REQUIRED
    $Subject = $Subject ; subject from the email - can be anything you want it to be
    $Body = $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 = "" ; $BccAddress ; address for bcc - leave blank if not needed
    $Importance = "Normal" ; Send message priority: "High", "Normal", "Low"
    $Username = "myaddress@gmail.com" ; 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 = 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($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
EndFunc   ;==>_SendEmail

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

please help me find what the problem can be!

Share this post


Link to post
Share on other sites



#3 ·  Posted

1 hour ago, kevin_amo said:

    ;$objEmail.To = $s_ToAddress

I guess the error was in this line were I commented it (;), because if this is uncommented I get another error:

error: missing separator character before keyword.

Also searched for this error through the forum and tried to install the latest versions, but still I get the error!

 

Share this post


Link to post
Share on other sites

#4 ·  Posted

33 minutes ago, Jos said:

What is the  MyErrFunc() telling you as that should contain more details?

Jos

 

;$objEmail.To = $s_ToAddress

I guess the error was in this line were I commented it (;), because if this is uncommented I get another error:

error: missing separator character before keyword.

Also searched for this error through the forum and tried to install the latest versions, but still I get the error!

Share this post


Link to post
Share on other sites

#5 ·  Posted

Don't start changing anything yet, but just check my question, or do you not have that Func MyErrFunc()   copied into you script? 
Check my original post in the Examples forum for the example of that Func.

When it is present and you run the script interactively, this function will display any COM error information telling more about why it is failing.

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#6 ·  Posted

1 minute ago, Jos said:

Don't start changing anything yet, but just check my question, or do you not have that Func MyErrFunc()   copied into you script? 
Check my original post in the Examples forum for the example of that Func.

When it is present and you run the script interactively, this function will display any COM error information telling more about why it is failing.

Jos

I have the error function, and when that line is commented there is no description for the error. It is just mentioned on the msgbox error: 2, description:.

but when I use your original smpt mailer function, i get the  error: missing separator character before keywor

at that line.

 

Share this post


Link to post
Share on other sites

#7 ·  Posted

6 minutes ago, Jos said:

Don't start changing anything yet, but just check my question, or do you not have that Func MyErrFunc()   copied into you script? 
Check my original post in the Examples forum for the example of that Func.

When it is present and you run the script interactively, this function will display any COM error information telling more about why it is failing.

Jos

Sorry my bad i get this description:

COM Error !  Number: 80020009   ScriptLine: 92   Description:At least one recipient is required, but none were found.

Share this post


Link to post
Share on other sites

#9 ·  Posted

yes it had, but this line: 

;$objEmail.To = $s_ToAddress

was commented at the beginning with (;).

so now when i remove the (;) from the beginning of the line i get the   error: missing separator character before keyword

Share this post


Link to post
Share on other sites

#11 ·  Posted

here is the complete error

"D:\Dropbox\MOOP\includes\email1.au3"(42,15) : error: missing separator character before keyword.

 

 

error.jpg

Share this post


Link to post
Share on other sites

#12 ·  Posted

Can you PM me your total script after only changing your password?
This way I can see what is going on as this error doesn't make sense to me yet. 

Jos


Visit the SciTE4AutoIt3 Download page for the latest versions        Beta files                                                          Forum Rules
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Share this post


Link to post
Share on other sites

#13 ·  Posted

$Password = "password; password for the account used from where the mail gets sent - REQUIRED

Shouldn't that be:

$Password = "password" ; password for the account used from where the mail gets sent - REQUIRED

 

Share this post


Link to post
Share on other sites

#14 ·  Posted

Just now, ffsidfk said:
$Password = "password; password for the account used from where the mail gets sent - REQUIRED

Shouldn't that be:

$Password = "password" ; password for the account used from where the mail gets sent - REQUIRED

 

that was a mistype when I was removing the password to copy it here!

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

@Jos thank you for your help!

this error was fixed by reinstalling Autoit!

error: missing separator character before keyword

 

 

Edited by kevin_amo

Share this post


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