For Windows Web Hosting packages

In this article, we'll show you how to send an email using the ASP Mail component.

ASP Mail is an Active Server component designed to send emails from an Active Server page. This component is installed by default on our Windows Web Hosting packages. Alternatively, you can also Send an Email Using ASP's CDOSYS.

Provided below is a sample ASP script that uses the ASP Mail component to send an authenticated (username and password required) test email.

Guided Steps
  • Copy the text from the box below and paste it into a text editor, such as NotePad.
  • Edit the top section of the script, making sure that you change all applicable values.
  • Save the file with the extension .asp (Ex: sendmail.asp).
  • Upload the file to your webspace.
  • Access the file through your browser to test that it works.

dim fromName, fromAddress, fromPassword, recipientName, recipientAddress, subject, body, sentTo

fromName        = "Test ASP Script"
fromAddress     = ""
fromPassword    = "Password for the Sender Goes Here"
recipientName   = "Recipient Name Goes Here"
recipientAddress= ""
subject         = "Enter a Subject Title Here!"
body            = "Enter the Body of the Mailing Here!"


sentTo = "NOBODY"
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = fromName
Mailer.FromAddress = fromAddress
Mailer.RemoteHost = ""
if Mailer.AddRecipient (recipientName, recipientAddress) then
sentTo=recipientName & " (" & recipientAddress & ")"
end if
Mailer.Subject = subject
Mailer.BodyText = body
if Mailer.SendMail then
Response.Write "The mailing was sent to: <b>" & sentTo & "</b>"
Response.Write "Mail send failure. Error was " & Mailer.Response
end if

If you are comfortable enough to edit the code above, you can also add additional parameters to the mailing, such as attachments, CC/BCCs, etc.:


Mailer.AddAttachment Server.MapPath("somefile.doc")

Attachments in a Subfolder

Mailer.AddAttachment Server.MapPath("subfolder/somefile.doc")

Carbon Copies (CC)

Mailer.AddCC "Susan Smith", ""

Blind Carbon Copies (BCC)

Mailer.AddBCC "John Smith", ""

Using a Text File for the Body of an Email

Mailer.GetBodyTextFromFile Server.MapPath("welcomeMail.txt"), True,False

Using a Text File in a Subfolder for the Body of an Email

Mailer.GetBodyTextFromFile Server.MapPath("subfolder/welcomeMail.txt"), True,False

Your new ASP script should work immediately upon accessing it through your browser. If it does not work or you receive an error message, carefully review the changes you have made to ensure there are no mistakes.