mfrom="abcd@abcd.com" rcpt="abcd@abcd.com, abcd@abcd.com" attachfile=null serverip="smtp.abcd.com" sbj="Subject" tbody="Hello World" Call SendMail(mfrom,rcpt,sbj,tbody,attachfile,serverIP)
Sub SendMail (mfrom,rcpt,sbj,tbody,attachfile,serverIP)
'######### call SendMail (mfrom,rcpt,cc,sbj,tbody,serverIP) ##################
'Use external smtp server to send mail
if trim(rcpt) = "" or trim(mfrom) = "" then
exit sub
end if
On Error Resume Next
Set objEmail = CreateObject("CDO.Message")
objEmail.From = mfrom
objEmail.To = rcpt
' objEmail.Cc = cc
' objEmail.Bcc = bcc
objEmail.Subject = sbj
objEmail.Textbody = tbody
'Sending an HTML e-mail:
' objEmail.HTMLBody = "
This is a message.
"
'Sending an HTML e-mail that sends a webpage from a website:
' objEmail.CreateMHTMLBody "file://c:/mydocuments/test.htm"
If Trim(attachfile) <> "" Then objEmail.AddAttachment attachfile
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = serverIP
objEmail.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
'-------Type of authentication, NONE, Basic (Base64 encoded), NTLM--------
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = cdoBasic
'-------Your UserID/Passwd on the SMTP server for SMTP auth for mail sent-----
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/sendusername") = "USER_NAME"
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "PASSWORD"
'-------Use SSL for the connection (False or True)---------
'objEmail.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)---------
'objEmail.Configuration.Fields.Item _
'("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Update
objEmail.Send
set objEmail=nothing
End Sub