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.
     

<%
'-----EDIT THE MAILING DETAILS IN THIS SECTION-----
dim fromName, fromAddress, fromPassword, recipientName, recipientAddress, subject, body, sentTo

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

'-----YOU DO NOT NEED TO EDIT BELOW THIS LINE-----

sentTo = "NOBODY"
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
function DayName (intDay)
  select case intDay
    case 1
      DayName = "Sun"
    case 2
      DayName = "Mon"
    case 3
      DayName = "Tue"
    case 4
      DayName = "Wed"
    case 5
      DayName = "Thu"
    case 6
      DayName = "Fri"
    case 7
    DayName = "Sat"
  end select
end function

function MonthName (intMonth)
  select case intMonth
    case 1
      MonthName = "Jan"
    case 2
      MonthName = "Feb"
    case 3
      MonthName = "Mar"
    case 4
      MonthName = "Apr"
    case 5
      MonthName = "May"
    case 6
      MonthName = "Jun"
    case 7
      MonthName = "Jul"
    case 8
      MonthName = "Aug"
    case 9
      MonthName = "Sep"
    case 10
      MonthName = "Oct"
    case 11
      MonthName = "Nov"
    case 12
      MonthName = "Dec"
  end select
end function
Set Mailer = Server.CreateObject("SMTPsvg.Mailer")
Mailer.FromName = fromName
Mailer.FromAddress = fromAddress
Mailer.Username = fromAddress
Mailer.Password = fromPassword
Mailer.RemoteHost = "mrelay.perfora.net"
Mailer.Port = 465
if Mailer.AddRecipient (recipientName, recipientAddress) then
sentTo=recipientName & " (" & recipientAddress & ")"
end if
Mailer.Subject = subject
Mailer.BodyText = body
Mailer.DateTime = DayName (WeekDay(Date)) & ", " & Day(Date) & " " & MonthName(Month(Date)) & " " & Year(Date) & " " & FormatDateTime(Now, 4) & " -0500 (EST)"
if Mailer.SendMail then
Response.Write "The mailing was sent to: <b>" & sentTo & "</b>"
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
%>

Please Note

  • Make sure the entire Mailer.DateTime entry is on a single line in your .asp file. Due to the parameters of this page and various size displays viewing it, it may incorrectly appear as 2 or more lines above and affect your ability to copy and paste it accurately.
  • If desired, the Mailer.DateTime line can be adjusted to fit your time zone. In the example above, it is set as EST.

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.:

Attachments

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


Attachments in a Subfolder

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

Carbon Copies (CC)

Mailer.AddCC "Susan Smith", "susan.smith@domain.com"

Blind Carbon Copies (BCC)

Mailer.AddBCC "John Smith", "john.smith@domain.com"

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.