SMTP Mail in VBA

R

Ray

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.
 
R

Ray

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 = "[email protected]"
objMessage.To = "[email protected]"
objMessage.TextBody = "This is a sample message text."
objMessage.Send
 
R

Ray

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") = "[email protected]"
.Item(strSch & "sendpassword") = "******"
.Update
End With

Set objCDOMessage = CreateObject("CDO.Message")
With objCDOMessage
Set .Configuration = objCDOConfig
.From = "ray"
.Sender = "[email protected]"
.To = "[email protected]"
.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.
 
Top