ASP Coding: Sending Email From
There are always people asking me how to send feedback or inquiry from their website to their email account.
Here’s one of the simple way for ASP hosted website, to send email via CDOSYS.
CDO (Collaboration Data Objects) is a Microsoft technology that is designed to simplify the creation of messaging applications.
CDOSYS is a built-in component in ASP.
Sample Code:
1) Sending TEXT email
<%
Set toMail=CreateObject("CDO.Message")
toMail.Subject="eMail from myWebsite"
toMail.From="yourmail@yourdomain.com"
toMail.To="someone@somedomain.com"
toMail.TextBody="This is a feedback/inquiry message."
toMail.Send
set toMail=nothing
%>
2) Sending TEXT email with cc and bcc
<%
Set toMail=CreateObject("CDO.Message")
toMail.Subject="Sending email from your website with cc and bcc"
toMail.From="yourmail@yourdomain.com"
toMail.To="someone@somedomain.com"
toMail.Bcc="someoneelse@somedomain.com"
toMail.Cc="someoneelse2@somedomain.com"
toMail.TextBody="This is a feedback/inquiry message."
toMail.Send
set toMail=nothing
%>
3) Sending HTML format email
<%
Set toMail=CreateObject("CDO.Message")
toMail.Subject="Sending HTML email"
toMail.From="yourmail@yourdomain.com"
toMail.To="someone@somedomain.com"
toMail.HTMLBody = "<h1>This is a HTML message.</h1>"
toMail.Send
set toMail=nothing
%>
4) Sending HTML email that send a webpage from a website
<%
Set toMail=CreateObject("CDO.Message")
toMail.Subject="Sending HTML email with Webpage"
toMail.From="yourmail@yourdomain.com"
toMail.To="someone@somedomain.com"
toMail.CreateMHTMLBody "http://www.it-paradise.com/"
toMail.Send
set toMail=nothing
%>
Hope the above do give you some basic knowledge on ASP.
Just found another example.
function CDOSYS_Mailer(Message, FromEmail, ToEmail, FromName, ToName,
Subject, MailerPath, MailerPort, errText, searchURL)
on error resume next
dim Mailer
set Mailer = server.createobject(“CDO.Message”)
if err.number <> 0 then
errText = displayError(“CDOSYS”, searchURL, err.Number, err.Source,
err.Description)
CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
exit function
end if
Mailer.From = FromName & ” < " & FromEmail & ">”
Mailer.To = ToName & ” < " & ToEmail & ">”
Mailer.TextBody = Message
Mailer.Subject = Subject
with Mailer.Configuration
.Fields(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
.Fields(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) =
MailerPath
.Fields(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) =
MailerPort
.Fields(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”)=1
.Fields(“http://schemas.microsoft.com/cdo/configuration/sendusername”)=”test@yourdomain.com”
.Fields(“http://schemas.microsoft.com/cdo/configuration/sendpassword”)=”youremailpassword”
.Fields.Update
end with
Mailer.Send
if err.number <> 0 then
errText = displayError(“CDOSYS”, searchURL, err.Number, err.Source,
err.Description)
CDOSYS_Mailer = false : set Mailer = nothing : err.clear() : err = 0
exit function
end if
set Mailer = Nothing
CDOSYS_Mailer = true
end function