How do I send email from a web page using ASPMail?

Using the ASPMail component to send a message from a web page is as simple as:

 - Creating the object
 - Setting a few properties
 - Calling the SendMail method

The following code demonstrates how to use AspMail from VBScript on a .asp web page. In this example, Joe from Joe’s Widgets wishes to send an email to John Smith. Joe’s outgoing SMTP server is located at smtp.mydomain.com.

Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName   = "Joe’s Widgets Corp."
Mailer.FromAddress= "
Joe@somehost.com"
Mailer.RemoteHost = "smtp.mydomain.com"
Mailer.AddRecipient "John Smith", "
jsmith@anotherhostname.com"
Mailer.Subject    = "Great SMTP Product!"
Mailer.BodyText   = "Dear Stephen" & VbCrLf & "Your widgets order _
 has been processed!"
if Mailer.SendMail then
  Response.Write "Mail sent..."
else
  Response.Write "Mail send failure. Error was " & Mailer.Response
end if

By testing the result of the SendMail method we can determine if the mailing process was successful or not.

Note: Change the RemoteHost parameter to use the name of your own domain.

RemoteHost = "smtp.mydomain.com"

When your website was first setup, two files were placed in your /scripts folder:

testmailform.asp
testmailsend.asp

Please reference these files for a complete working example.

For full documentation and more examples of using ASPMail, please visit ServerObjects.com 

Add Feedback