1. Home
  2. Scripting
  3. Sending email within ASP using CDOSYS

Sending email within ASP using CDOSYS

CDOSYS is an inbuilt component within ASP itself, so there are no additional programs or plug-ins needed.


Sample code (edit the sections that LOOK_LIKE_THIS):

<%
If Request.Form(“submit”) <> “” Then
Set myMail=CreateObject(“CDO.Message”)
myMail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusing”) = 2
myMail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserver”) = “dwebform.pipeten.co.uk”
myMail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpserverport”) = 25
myMail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/smtpauthenticate”) = 0
myMail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendusername”) = “”
myMail.Configuration.Fields.Item(“http://schemas.microsoft.com/cdo/configuration/sendpassword”) = “”
myMail.Configuration.Fields.Update
myMail.Subject= “CONTACT_US_FROM_WEBSITE” ‘This is the subject of the e-mail
myMail.To=”YOUR_EMAIL@MAIL.COM” ‘This is the e-mail address the e-mail will be delivered to
myMail.From=Request.Form(“emaddress”)
myMail.TextBody=”Name: ” & Request.Form(“name”) & vbnewline & “E-Mail Address: ” & Request.Form(“emaddress”) & vbnewline & “Message: ” & Request.Form(“message”)
myMail.Send
set myMail=nothing
Response.Redirect(“THANK_YOU_PAGE.html“)
End If
%>
<html>
<head>
<title>Contact Us</title>
</head>
<body>
<form method=”POST” action=””>
<p>
Name: <input type=”text” name=”name” size=”20″><br>
E-mail Address: <input type=”text” name=”emaddress” size=”20″><br>
Message: <input type=”text” name=”message” size=”80″>
</p>
<p>
<input type=”submit” value=”Submit” name=”submit”>
<input type=”reset” value=”Reset” name=”reset”>
</p>
</form>
</body>
</html>

Save the above code in your favourite editor as an .asp file then upload to your website. Please be aware that when sending emails from your website, if you have the option to specify the outgoing server you should use web form, our specialised mail server.

You will also need to create your own thank you page that the user is redirected to once they have submitted the form. You can call this whatever you like, just remember to update the URL in the code from THANK_YOU_PAGE.html to your page name.

Click here for full details

Classification: Public
Last saved: 2019/08/14 at 15:14 by Jamie

How can we help?