Sending email with CDO from Access

This is a discussion on Sending email with CDO from Access within the ms-access forums in Other Databases category; 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 ...

Go Back   Database Forum > Other Databases > ms-access

Database Forums

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 08-26-2008, 02:14 PM
Default Sending email with CDO from Access

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") = "address-at-mycompany.com"
flds.Item(schema & "sendpassword") = "123abc456"
flds.Item(schema & "smtpusessl") = 1
flds.Update

With imsg
..To = "evancater-at-juno.com"
..From = "Sender "
..Subject = "Test send"
..HTMLBody = "Test"
..Sender = "Sender"
..Organization = "My Company"
'.ReplyTo = "address-at-mycompany.com"
Set .Configuration = iconf
..Send
End With

Set iconf = Nothing
Set imsg = Nothing
Set flds = Nothing
End Sub
-----------------------------------------------------------------------------------------
Reply With Quote
  #2  
Old 08-26-2008, 04:09 PM
Default Re: Sending email with CDO from Access

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 wrote:
> 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 "
> .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
> ---------------------------------------------------------------------------*--------------


Reply With Quote
  #3  
Old 08-26-2008, 06:05 PM
Default Re: Sending email with CDO from Access

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



Reply With Quote
  #4  
Old 08-26-2008, 07:40 PM
Default Re: Sending email with CDO from Access

"evenlater" wrote in message
news:d67a5744-a594-4dcd-b3e0-7051c415a26a-at-v39g2000pro.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") = "address-at-mycompany.com"
> flds.Item(schema & "sendpassword") = "123abc456"
> flds.Item(schema & "smtpusessl") = 1
> flds.Update
>
> With imsg
> .To = "evancater-at-juno.com"
> .From = "Sender "
> .Subject = "Test send"
> .HTMLBody = "Test"
> .Sender = "Sender"
> .Organization = "My Company"
> '.ReplyTo = "address-at-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.


Reply With Quote
  #5  
Old 08-26-2008, 10:10 PM
Default Re: Sending email with CDO from Access

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


Reply With Quote
  #6  
Old 08-26-2008, 10:49 PM
Default Re: Sending email with CDO from Access

On Tue, 26 Aug 2008 10:14:18 -0700 (PDT), evenlater
wrote:

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") = "address-at-mycompany.com"
>flds.Item(schema & "sendpassword") = "123abc456"
>flds.Item(schema & "smtpusessl") = 1
>flds.Update
>
>With imsg
>.To = "evancater-at-juno.com"
>.From = "Sender "
>.Subject = "Test send"
>.HTMLBody = "Test"
>.Sender = "Sender"
>.Organization = "My Company"
>'.ReplyTo = "address-at-mycompany.com"
>Set .Configuration = iconf
>.Send
>End With
>
>Set iconf = Nothing
>Set imsg = Nothing
>Set flds = Nothing
>End Sub
>-----------------------------------------------------------------------------------------

Reply With Quote
  #7  
Old 08-28-2008, 09:02 PM
Default Re: Sending email with CDO from Access

evenlater wrote:

>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/
Reply With Quote
Reply


Thread Tools
Display Modes



All times are GMT -4. The time now is 02:42 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Integrated by bbpixel2008 :: jvbPlugin R1013.368.1

Search Engine Friendly URLs by vBSEO 3.1.0
vB Ad Management by =RedTyger=
In an effort to better serve ads to our visitors, cookies are used on Mydatabasesupport.com. For more information, check out our Privacy Policy.