Here is some generic code that works well on any SMTP server. You will need to supply the proper port, etc. I used variables for the Sender, To, etc.
'--------------------------
Const cdoSendUsingPickup = 1 'Send message using the local SMTP service pickup directory.
Const cdoSendUsingPort = 2 'Send the message using the network (SMTP over the network).
Const cdoAnonymous = 0 'Do not authenticate
Const cdoBasic = 1 'basic (clear-text) authentication
Const cdoNTLM = 2 'NTLM
Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = strSubject
objMessage.Sender = strSender
objMessage.To = strTo
objMessage.TextBody = "Add Text Here or use variable with message."
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") = "mail.YourDomain.com"
'Type of authentication, NONE, Basic (Base64 encoded), NTLM
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'Your UserID on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusername") = "****" 'nothing on ours, maybe something on yours.
'Your password on the SMTP server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "****" 'nothing on ours, maybe something on yours
'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'Use SSL for the connection (False or True)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = False
'Connection Timeout in seconds (the maximum time CDO will try to establish a connection to the SMTP server)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objMessage.Configuration.Fields.Update
'==End remote SMTP server configuration section==
objMessage.sEnd
'------------------------
You want to make sure you declare your variables first. Then take the values from the form. For example, if you have a textbox with the receiver's email address, just make it invisible on the form, but take the value like this:
strTo = Me.txtUsersEmail
Or from a hidden column in a combo box (let's say the 3rd column)
strTo = Me.cboUser.Column(3) 'I think that is right, it will auto complete for you in VBA.
You Can take other items from the form, and have your message already in the code, etc.
Does this help?
mmcdonal
|