Sending Email from Access
I have an access 2000 Database, I am running Windows XP pro and MS office 2003 Pro. With in my Database I want to be able to send emails off of the server and not using the local email client. I have tried several pieces of code and have searched high and low for something that works. HEre is what I have now:
1st try:
VB Code:
Public Sub xSendEmail(ByVal sSubject As String, ByVal sRecipient As String, ByVal sSender As String, ByVal sBody As String)
'MailMessage
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = sSubject
objMessage.Sender = sSender
objMessage.To = sRecipient
objMessage.TextBody = sBody
'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "server name"
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.Send
Set objMessage = Nothing
End Sub
2nd try
VB Code:
Sub SendEmail(ByVal sSubject As String, ByVal sRecipient As String, ByVal sSender As String, ByVal sBody As String)
SMTP_CONNECTION_TIMEOUT = 30
SMTP_SERVER_PORT = 25 ' Set the port to communicate on
SMTP_SERVER_NAME = "server name"
CDO_USER_NAME = "" 'This can be an empty string
CDO_USER_PASSWORD = "" 'This can be an empty string
Set objConfig = New CDO.Configuration
' Set the configuration fields for this message.
With objConfig.Fields
.Item(cdoSendUsingMethod) = cdoSendUsingPort
.Item(cdoSMTPServer) = SMTP_SERVER_NAME
.Item(cdoSMTPConnectionTimeout) = SMTP_CONNECTION_TIMEOUT
.Item(cdoSMTPServerPort) = SMTP_SERVER_PORT
.Item(cdoSendUserName) = CDO_USER_NAME
.Item(cdoSendPassword) = CDO_USER_PASSWORD
.Update
End With
' Create the new message object.
Set objMessage = New CDO.Message
' Set the message properties and send the message.
With objMessage
Set .Configuration = objConfig
.MimeFormatted = True
.To = sRecipient
.CC = "" 'Add CC recipients as applicable.
.BCC = "" 'Add BCC recipients as applicable.
.From = sSender 'This needs to be a valid user on SMTP_SERVER_NAME.
.Subject = sSubject
' If Dir(strAttachment) <> "" Then
' .AddAttachment strAttachment
' End If
'.TextBody = strMessage 'Use this if you want to send email as plain text.
.HTMLBody = sBody
.Fields.Update
.Send
End With
Set objMessage = Nothing
Set objConfig = Nothing
End Sub
It appears that I am able to send from my machine but when I go to someone elses machine it no longer works.
Re: Sending Email from Access
Any error messages?
Check the references, might be the other machine doesn't have cdo?
Debug your proggy, step through (if poss) and see where it is failing?
If you are running the app and not debugging, perhaps writing to a text file as actions are made to assist in debugging?
Re: Sending Email from Access
Error: Transport failed to connect with server.
is the error on the .send