[RESOLVED] CDO.Message not working in Win7.64bit
Hi members
Though this forum i had just been able to use "Ms CDO for Exchange 2000 Libary" to send email via gmail STMP server in PC's running XPWin.sp2-3. This is done after CreateObject("CDO.Configuration") with all the appropriate Fields referring to "http://schemas.microsoft.com/cdo/configuration/" followed by object CDO.Message .send.
However when i do exactly the same thing in Win7.64bit, error message "From or Sender Field missing" at the point of .send. There was no error in .Update of Configuration.
The difference i note is the reference in made to C:\windows\sysWOW64\CDOEX.DLL which is however exactly the same as that found in WinXp.
I had search the web and is unable to find a solution. Again need help from my senior peers. Thanks.
Re: CDO.Message not working in Win7.64bit
default values that may have been valid in xp systems, may need to be specified in win7, as there is no inbuilt mail client
have you assigned values to the from or sender fields?
as we do not see your code hard to guess
gmail does not allow spoofing of the senders email address, it will always be forwarded as [email protected]
Re: CDO.Message not working in Win7.64bit
Thanks West
The codes i use that work in XPWin.sp3 but failed in win7.64bit are as follows:
Dim MsSchm$, Cd0Conf as object, CdoMsg as object
MsSchm$ = "http://schemas.microsoft.com/cdo/configuration/"
Set Cd0Conf = CreateObject("CDO.Configuration")
With Cd0Conf.Fields
.Item(MsSchm$ & "smtpauthenticate") = 1
.Item(MsSchm$ & "smtpusessl") = True
.Item(MsSchm$ & "smtpserver") = "smtp.gmail.com"
.Item(MsSchm$ & "sendusername") = "[email protected]"
.Item(MsSchm$ & "sendpassword") = "senderPassword"
.Item(MsSchm$ & "smtpserverport") = 465
.Item(MsSchm$ & "sendusing") = 2
.Item(MsSchm$ & "connectiontimeout") = 100
.Update
End With
Set CdoMsg = CreateObject("CDO.Message")
With CdoMsg
Set .Configuration = Cd0Conf
.From = "senderName"
.To = "[email protected]"
.Subject = "This Test"
.TextBody = "Testing"
.Send
End With
Re: CDO.Message not working in Win7.64bit
there are different fields in the configuration for xp to w7
in xp there is a field senderemailaddress, that is likely to hold a default value from outlook or outlook express, i do not find this field in w7 configuration fields
you must specify an email address in either the from or sender properties of the email
no matter what email address you put, the recipient will see [email protected]
Quote:
Subject: This Test
From: "senderName" <
[email protected]>
Date: Wed, June 15, 2011 6:44 pm
To: xxxxxxxxxxxxxxxx
Priority: Normal
Options: View Full Header | View Printable Version
Testing
sent from w 7 using your code, with slight modification
my gmail acct and password
my address in .to
my as above (not gmail) address as .sender
Re: CDO.Message not working in Win7.64bit
Quote:
Originally Posted by
westconn1
there are different fields in the configuration for xp to w7
I'm pretty sure this isn't true.
Quote:
Originally Posted by
westconn1
in xp there is a field senderemailaddress, that is likely to hold a default value from outlook or outlook express, i do not find this field in w7 configuration fields
I think you mean cdoSendEmailAddress, which is the named predefined constant for this field. It is almost always better to use he predefined constants instead of magic strings and numbers.
Yes, this field is legal in Win2K, XP, Vista, Windows 7, and contemporary Server versions of Windows. However it applies to the SMTP Envelope of an inbound message received using the IIS SMTP Service which does not apply here, and not the Configuration.
This is probably a lot closer to a working example, done properly instead of using hacked up Field name strings and magic number values:
Code:
Option Explicit
'
'For Windows 2000 or later. Requires a reference to:
'
' Microsoft CDO For Windows Library
'
Private Sub SendMsg()
Dim cdoMsg As New CDO.Message
With cdoMsg
With .Configuration.Fields
.Item(cdoSendUsingMethod).Value = cdoSendUsingPort
.Item(cdoSMTPServerPort).Value = 465
.Item(cdoSMTPServer).Value = "smtp.gmail.com"
.Item(cdoSendUserName).Value = "senderName"
.Item(cdoSendPassword).Value = "senderPassword"
.Item(cdoSMTPAuthenticate).Value = cdoBasic
.Update
End With
.From = "[email protected]"
.To = "[email protected]"
.Subject = "This Test"
.TextBody = "Testing"
On Error Resume Next
.Send
End With
If Err.Number <> 0 Then
MsgBox "CDO error " & Hex$(Err.Number) & vbNewLine & Err.Description, _
vbOKOnly Or vbExclamation
Else
MsgBox "Mail sent!", vbOKOnly
End If
End Sub
Private Sub Command1_Click()
SendMsg
End Sub
Re: CDO.Message not working in Win7.64bit
Quote:
I'm pretty sure this isn't true.
i went through the fields list on each and compared
to produce a list i would have to do on separate computers
here is the list from xp
on the w7 i found no field for sendemailaddress,
from w7
the difference is, which fields are set by default in the different os, other fields appear in the list when set
as most times i use cdo, it is from vbs i tend not to use the constants
Quote:
error message "From or Sender Field missing"
i thought this error message was amazingly clear and unambiguous, most unusual
Re: CDO.Message not working in Win7.64bit
In your previous post you said senderemailaddress which is an entirely different thing.
The difference in Configuration fileds you are seeing is not because of Windows 7, but because you have no email client installed on your Windows 7 computer that CDO recognizes as a Configuration source. In XP you almost certainly have at least Outlook Express present.
Quote:
error message "From or Sender Field missing"
Yes, this tells you exactly where the problem is: wrong syntax value supplied for:
.Item(cdoSendUserName).Value, or
.From
... or in this case both. See my previous post.
Re: CDO.Message not working in Win7.64bit
Many Thanks gurus; need some testing to fully understand what transpired between the 2 of you. Dilettante: will try not use "hacked up Field name strings and magic number values" for better coding as tutored. Cheers!
PS Dilettante:
After playing with your codes which i think smarter, it however gave an CDO error 80040213 in XpWin. The codes i listed above however works fine. Can you have another look at yr codes if there is something missing.
Re: CDO.Message not working in Win7.64bit
Yes, that's probably true enough. I think you need this line:
Code:
.Item(cdoSMTPUseSSL).Value = True
That got left out of my sample, which came from a working test program that does not send to GMail so it didn't need that set to True.
Your error's description goes like:
Quote:
The transport failed to connect to the server
... and from there the problem should have been easy enough to diagnose.
Re: CDO.Message not working in Win7.64bit
Quote:
Originally Posted by
westconn1
as most times i use cdo, it is from vbs i tend not to use the constants
That might sound good, except that if by "VBS" you really mean WSH scripts or ASP pages the constants can be available there as well, and you can even predeclare the COM objects involved. You merely need to set a reference using the techniques each script host supports.
You can even create multiline text resources easily!
For WSH that means using .WSF files instead of the obsolete .VBS file format that went out of style in 1999.
Example CDO.wsf:
Code:
<job>
<reference object="CDO.Configuration" />
<object id="Msg" progID="CDO.Message" />
<object id="Config" progID="CDO.Configuration" />
<resource id="MsgSubject">CDO Test</resource>
<resource id="MsgBody">Greetings Earthling!
This is a test message sent via CDOSYS to ensure that it can still
be done from recent versions of Windows.
This is only a test.</resource>
<script language="VBScript">
Option Explicit
Const SMTPServer = "MAIL.YOURDOMAIN.COM"
Const SMTPProxyByPass = "<local>" 'Don't use proxy server.
Const SMTPAccount = "YOURACCOUNT"
Const SMTPPassword = "YOURPASSWORD"
Const SMTPSource = """FRIENDLY NAME"" <[email protected]>"
Const SMTPDestination = """SOME GUY"" <[email protected]>"
With Config.Fields
.Item(cdoSendUsingMethod).Value = cdoSendUsingPort
.Item(cdoSMTPServer).Value = SMTPServer
.Item(cdoSMTPConnectionTimeout).Value = 10 'Quick timeout
.Item(cdoURLGetLatestVersion).Value = True 'Ignore cached URL resources.
.Item(cdoURLProxyBypass).Value = SMTPProxyByPass
.Item(cdoSMTPAuthenticate).Value = cdoBasic
.Item(cdoSendUserName).Value = SMTPAccount
.Item(cdoSendPassword).Value = SMTPPassword
.Update
End With
With Msg
Set .Configuration = Config
.From = SMTPSource
.To = SMTPDestination
.Subject = getResource("MsgSubject")
.TextBody = getResource("MsgBody")
On Error Resume Next
.Send
End With
If Err.Number <> 0 Then
WScript.Echo "CDO Send error: " & Hex(Err.Number) & vbNewLine _
& Err.Description
Else
WScript.Echo "Email sent."
End If
</script>
</job>
Re: CDO.Message not working in Win7.64bit
Thanks Dilettante:
You are right, i had earlier tested with .Item(cdoSMTPUseSSL).Value = True which was left out in yr sample & then it worked.
Meanwhile i may have to say sorry for misleading both of you West/Dilettante that cdo don't work in win7.64bit as i just found out the my firewall was actually blocking the access to the server coming from a VB6 .exe.
I will confirm this later and if so i will mark this thread as resolved.
PS Latest: Beside the block by the firewall, the other important thing is to use in .to the full address & not just the name ie use .to = "[email protected]"
Re: [RESOLVED] CDO.Message not working in Win7.64bit
Whew!
The main thing you have it resolved and can move forward.
Re: [RESOLVED] CDO.Message not working in Win7.64bit
Error message: %1 is not a valid Win32 application
See topic: CDO.Message not working in 64bit