SMTP Mail in VBA

G

Guest

I remember using some code to send SMTP mail using VBA. I don't want to send
it thru Outlook or Lotus Notes. Can you refresh my memory on the code I use
to send SMTP mail?
 
R

Ron Weiner

Ray

There is a sample fir sending mail using CDO here
http://www.WorksRite.com/CDOMail.htm. CDO is installed as part of the OS on
Win 2K, and Xp. If you users are using Win 98 orWin ME then they will have
had to install Outlook 98 or higher else they will NOT have CDO installed
thereby causing this code to fail.
 
G

Guest

The link is no longer active but I found this code. it all works until the
last line. I get error in the "objMessage.Send" line

Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.Sender = "(e-mail address removed)"
objMessage.To = "(e-mail address removed)"
objMessage.TextBody = "This is a sample message text."
objMessage.Send
 
G

Guest

have just modified the code as follows. the ".send" still errors. can i be
missing a reference or something?

Const cdoSendUsingPort = 2
Const cdoBasic = 1
Dim objCDOConfig As Object, objCDOMessage As Object
Dim strSch As String

strSch = "http://schemas.microsoft.com/cdo/configuration/"
Set objCDOConfig = CreateObject("CDO.Configuration")
With objCDOConfig.Fields
.Item(strSch & "sendusing") = cdoSendUsingPort
.Item(strSch & "smtpserver") = "SMTP.comcast.net"
' Only used if SMTP server requires Authentication
.Item(strSch & "smtpauthenticate") = cdoBasic
.Item(strSch & "sendusername") = "(e-mail address removed)"
.Item(strSch & "sendpassword") = "******"
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.From = "ray"
.Sender = "(e-mail address removed)"
.To = "(e-mail address removed)"
.Subject = "Sample CDO Message"
.TextBody = "This is a test for CDO message"
.Send
End With
Set objCDOMessage = Nothing
Set objCDOConfig = Nothing
 
R

Ron Weiner

What is the Error Message?

Is "SMTP.comcast.net" the server that handles your POP mail?
Are you sure that you have your Username and Password set correctly?
What is the OS yo are using?

This code uses late binding and therefore does not require a reference.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top