By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,967 Members | 1,710 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,967 IT Pros & Developers. It's quick & easy.

Sending email with CDO from Access

P: n/a
I'm trying to send an email from an Access procedure using CDO. I've
been able to do it successfully with three different sending email
addresses, but not with the email address I actually need to use in
production. In that case I get a message saying "The transport failed
to connect to the server." I've tried several different ports. Anybody
have any idea what the problem might be? My code is below.

-----------------------------------------------------------------------------------------
Public Sub SendEmail()
Dim imsg As Message
Dim iconf As Object
Dim flds As Object
Dim schema As String

Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields

' send one copy with SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "mail2.mycompany.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "ad*****@mycompany.com"
flds.Item(schema & "sendpassword") = "123abc456"
flds.Item(schema & "smtpusessl") = 1
flds.Update

With imsg
..To = "ev*******@juno.com"
..From = "Sender <ad*****@mycompany.com>"
..Subject = "Test send"
..HTMLBody = "Test"
..Sender = "Sender"
..Organization = "My Company"
'.ReplyTo = "ad*****@mycompany.com"
Set .Configuration = iconf
..Send
End With

Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub
-----------------------------------------------------------------------------------------
Aug 26 '08 #1
Share this Question
Share on Google+
6 Replies


P: n/a
THis usually happens to me when I don't give the SMTP server the
information it needs in the form it needs.

BTW, your code uuse both late binding and early binding. That probably
has nothing to do with your problem, it's just très ugly.
On Aug 26, 1:14*pm, evenlater <evanca...@gmail.comwrote:
I'm trying to send an email from an Access procedure using CDO. I've
been able to do it successfully with three different sending email
addresses, but not with the email address I actually need to use in
production. In that case I get a message saying "The transport failed
to connect to the server." I've tried several different ports. Anybody
have any idea what the problem might be? My code is below.

---------------------------------------------------------------------------*--------------
Public Sub SendEmail()
Dim imsg As Message
Dim iconf As Object
Dim flds As Object
Dim schema As String

Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields

' send one copy with SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "mail2.mycompany.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "addr...@mycompany.com"
flds.Item(schema & "sendpassword") = "123abc456"
flds.Item(schema & "smtpusessl") = 1
flds.Update

With imsg
.To = "evanca...@juno.com"
.From = "Sender <addr...@mycompany.com>"
.Subject = "Test send"
.HTMLBody = "Test"
.Sender = "Sender"
.Organization = "My Company"
'.ReplyTo = "addr...@mycompany.com"
Set .Configuration = iconf
.Send
End With

Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub
---------------------------------------------------------------------------*--------------
Aug 26 '08 #2

P: n/a
Thanks. I'm new at this... how would I change it to use either late or
early binding?

On Aug 26, 2:09 pm, lyle fairfield <lyle.fairfi...@gmail.comwrote:
THis usually happens to me when I don't give the SMTP server the
information it needs in the form it needs.

BTW, your code uuse both late binding and early binding. That probably
has nothing to do with your problem, it's just très ugly.

Aug 26 '08 #3

P: n/a
"evenlater" <ev*******@gmail.comwrote in message
news:d6**********************************@v39g2000 pro.googlegroups.com...
I'm trying to send an email from an Access procedure using CDO. I've
been able to do it successfully with three different sending email
addresses, but not with the email address I actually need to use in
production. In that case I get a message saying "The transport failed
to connect to the server." I've tried several different ports. Anybody
have any idea what the problem might be? My code is below.

-----------------------------------------------------------------------------------------
Public Sub SendEmail()
Dim imsg As Message
Dim iconf As Object
Dim flds As Object
Dim schema As String

Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields

' send one copy with SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "mail2.mycompany.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "ad*****@mycompany.com"
flds.Item(schema & "sendpassword") = "123abc456"
flds.Item(schema & "smtpusessl") = 1
flds.Update

With imsg
.To = "ev*******@juno.com"
.From = "Sender <ad*****@mycompany.com>"
.Subject = "Test send"
.HTMLBody = "Test"
.Sender = "Sender"
.Organization = "My Company"
'.ReplyTo = "ad*****@mycompany.com"
Set .Configuration = iconf
.Send
End With

Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub
-----------------------------------------------------------------------------------------
Because you're using late binding (ie CreateObject), and have no reference
set to the CDO library, the following constants are not defined:

Const cdoSendUsingPort = 2
Const cdoBasic = 1

Insert those 2 lines at the top of your procedure and give that a try.
Aug 26 '08 #4

P: n/a
At http://www.ffdba.com/downloads/Send_E-Mail_With_CDO.htm
there are two examples. One is all early-binding and the other is all
late.

On Aug 26, 5:05*pm, evenlater <evanca...@gmail.comwrote:
Thanks. I'm new at this... how would I change it to use either late or
early binding?

On Aug 26, 2:09 pm, lyle fairfield <lyle.fairfi...@gmail.comwrote:
THis usually happens to me when I don't give the SMTP server the
information it needs in the form it needs.
BTW, your code uuse both late binding and early binding. That probably
has nothing to do with your problem, it's just très ugly.
Aug 27 '08 #5

P: n/a
On Tue, 26 Aug 2008 10:14:18 -0700 (PDT), evenlater
<ev*******@gmail.comwrote:

Try this:
flds.Item(schema & "sendusername") = "address"
Just yesterday that helped us with some ISP.

Of course the u/pw is only needed if the SMTP server requires it.

-Tom.
Microsoft Access MVP
>I'm trying to send an email from an Access procedure using CDO. I've
been able to do it successfully with three different sending email
addresses, but not with the email address I actually need to use in
production. In that case I get a message saying "The transport failed
to connect to the server." I've tried several different ports. Anybody
have any idea what the problem might be? My code is below.

-----------------------------------------------------------------------------------------
Public Sub SendEmail()
Dim imsg As Message
Dim iconf As Object
Dim flds As Object
Dim schema As String

Set imsg = CreateObject("CDO.Message")
Set iconf = CreateObject("CDO.Configuration")
Set flds = iconf.Fields

' send one copy with SMTP server (with autentication)
schema = "http://schemas.microsoft.com/cdo/configuration/"
flds.Item(schema & "sendusing") = cdoSendUsingPort
flds.Item(schema & "smtpserver") = "mail2.mycompany.com"
flds.Item(schema & "smtpserverport") = 25
flds.Item(schema & "smtpauthenticate") = cdoBasic
flds.Item(schema & "sendusername") = "ad*****@mycompany.com"
flds.Item(schema & "sendpassword") = "123abc456"
flds.Item(schema & "smtpusessl") = 1
flds.Update

With imsg
.To = "ev*******@juno.com"
.From = "Sender <ad*****@mycompany.com>"
.Subject = "Test send"
.HTMLBody = "Test"
.Sender = "Sender"
.Organization = "My Company"
'.ReplyTo = "ad*****@mycompany.com"
Set .Configuration = iconf
.Send
End With

Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub
-----------------------------------------------------------------------------------------
Aug 27 '08 #6

P: n/a
evenlater <ev*******@gmail.comwrote:
>Thanks. I'm new at this... how would I change it to use either late or
early binding?
I'd suggest late binding once you've got the code debugged.

Late binding means you can safely remove the reference and only have an error when
the app executes lines of code in question. Rather than erroring out while starting
up the app and not allowing the users in the app at all. Or when hitting a mid, left
or trim function call.

This also is very useful when you don't know version of the external application
will reside on the target system. Or if your organization is in the middle of moving
from one version to another.

For more information including additional text and some detailed links see the "Late
Binding in Microsoft Access" page at http://www.granite.ab.ca/access/latebinding.htm

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
Tony's Microsoft Access Blog - http://msmvps.com/blogs/access/
Aug 29 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.