473,473 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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") = "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
6 15029
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
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
"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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Deborah V. Gardner | last post by:
I am trying to send email from Access 2000 using Eudora. The MAPI option is set in Eudora to always be the MAPI server. When I use the Send option on the File menu I receive an message...
2
by: Del | last post by:
I have two question on sending email messages from MS Access (Versio 2000, 2002, and 2003). I have a form with a command button to send an email message, the code behide the button is as follows;...
7
by: Marcin | last post by:
Hello all! A few years ago I created a form with button which let me send an email with an attachment. It was created in Access 97. Now I would like to move this application into Access 2003....
17
by: Bonj | last post by:
Right guys. (I would like a solution to this in VB6 as this is what our needy app is written in, but any solutions that involve .NET would be much appreciated likewise as I could instantiate...
1
by: xin.yadong | last post by:
Hi: I have a shared function for sending Email using SMTP. It works fine in a ASP.NET web application. But when I use it in a VB.Net Windows application, it always gave me an error: "Could not...
1
by: Mose | last post by:
Greetings! I am using Access '97 to track company orders. It's a pretty basic setup featuring a main table (tbl_SalesSlip) and a related table (tbl_ModelsSold). I would like to send an email that...
2
by: Nathan Sokalski | last post by:
I have an ASP.NET 2.0 application that is supposed to send an email after a certain form is submitted. When it tries to send the email, I receive the following error: Transaction failed. The...
31
by: happyse27 | last post by:
Hi All, I am trying for weeks how to send email from windows pc, which from my gmail account to my hotmail account. Using net::smtp module sending email failed,Kindly assist. (for the item d it...
6
by: Chocolade | last post by:
Hi, Im using System.Net.Mail to send email in my application it was working great without any problems untill this morning after like 20-30 tries it was sending the email ok then suddenly this...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.