Sign in to follow this  
Followers 0
hypertyper

Win XP sending email ==> Variable must be of type "Object".

4 posts in this topic

#1 ·  Posted (edited)

==> Variable must be of type "Object".:
$_ObjEmail.From = '"' & $_FromName & '" <' & $_FromAddress & '>'
$_ObjEmail^ ERROR

I'm using the following script which works on my Win7 machine but not my WinXP Laptop and that's where I need it. I don't get an error in Win7 and on XP it just doesn't work. What am I doing wrong? In another thread somebody had the same problem and resolved it by installing some files that were missing on his machine but he never replied about what it was. I couldn't find anything else on the topic.

Thanks for your time.

;
;##################################
; Include
;##################################
#Include<file.au3>
Global $oMyRet[2]
Global $oMyError = ObjEvent("AutoIt.Error", "ErrFunc")


Dim $s_SmtpServer = "smtp.gmail.com" ; address for the smtp-server to use - REQUIRED
Dim $s_FromName = "Peter Pan" ;IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "FromName", "") ; name from who the email was sent
Dim $s_FromAddress = "xxxx@gmail.com" ;IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "FromAddress", "") ; address from where the mail should come
Dim $s_ToAddress = "xxxx@gmail.com" ;IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "ToAddress", "") ; destination address of the email - REQUIRED
Dim $s_Subject = "test" ;IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "Subject", "") ; subject from the email - can be anything you want it to be
Dim $as_Body = "testboddy" ; the message body from the mail - can be left blank but then you get a blank mail
Dim $as_BodyTemp = "huh" ; the temporary message body as the file is being read and compiled
Dim $s_AttachFiles = "";@ScriptDir & "\capterrFail 28_01.txt" ; the file you want to attach - leave blank if not needed
Dim $s_CcAddress = "";IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "ccAddress", "") ; address for cc - leave blank if not needed
Dim $s_BccAddress = "" ; address for bcc - leave blank if not needed
Dim $s_Username = "xxxx@gmail.com" ;IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "Username", "") ; username for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
Dim $s_Password = "xxxxx" ;_StringEncrypt(0, IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "Password", ""), $EncryptKey, 1) ; password for the account used from where the mail gets sent  - Optional (Needed for eg GMail)
Dim $IPPort = 465 ;IniRead(@ScriptDir & "\runmgr.ini", "SMTP", "Port", "") ; port used for sending the mail
Dim $ssl = 1 ; use secure socket layer sending (ssl) "SMTP", "Port", "") ; port used for sending the mail


_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)

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, $ssl)
;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

; send the message
    $objEmail.Send
    If @error Then
        SetError(2)
        return $oMyRet[1]
    EndIf
EndFunc
Edited by hypertyper

Share this post


Link to post
Share on other sites



There is no $_objEmail in that code, so that error is not copied from running the code shown.

The closest you have is this:

$objEmail = ObjCreate("CDO.Message")
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'

That simply requires checking the success of your ObjCreate() before trying to use the object:

$objEmail = ObjCreate("CDO.Message")
    If Not IsObj($objEmail) Then
        MsgBox(16, "Error", "Failed to create CDO.Message object.")
        Return SetError(1, 0, 0)
    EndIf
    $objEmail.From = '"' & $s_FromName & '" <' & $s_FromAddress & '>'

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Thanks for your reply. You are right, error wasn't from this exact script. I was playing around with similar scripts and one had the "_" and the other didn't. However, running the exact script posted (with the edited error message) still doesn't work. When I put in you error check then I get the popup :|

What gets used to create the obj? Any .net framework something along the lines? I've tried the script on another XP machine, same version, and it somehow worked. I have no idea what the difference is. It has nothing to do with the script so it must be something Windows related.

edit: the PC where it works doesn't even have .net framework on it right now. It's a pretty fresh install so it's almost naked. I'm clueless.

Thanks

edit: It now works on the Laptop where I need it and I've changed nothing. This is so weird. I'm running the same executable getting different results. Say What???

Edited by hypertyper

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
Sign in to follow this  
Followers 0