1and1 Help Centre Categories

print article

Send an E-Mail Using ASPMail

In this article you will learn how to send E-mail messages through ASPMail.

ASPMail is an Active Server Component designed to send E-mails from an Active Server Page. This component is installed and available on our web hosting packages.

Follow the steps below to send an E-mail using the ASPMail programme.

Step 1
Copy the entire text from within the box below and paste it into a text editor.
Step 2
Edit the top section of the script changing the recipient address to your own E-mail address.
Step 3
Save the text file as sendmail.asp.
Step 4
Upload the file to your webspace.
Step 5
Access the file through your web browser using the correct URL.

Below is a sample ASP script that uses the ASPMail component to send an unauthenticated (no username or password required) test E-mail.

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

fromName        = "Test ASP Script"
fromAddress     = "address@domain.co.uk"
recipientName   = "Your Name Goes Here"
recipientAddress= "yourEmailAddress@yourDomain.co.uk"
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")
Mailer.FromName = fromName
Mailer.FromAddress = fromAddress
Mailer.RemoteHost = "mrelay.perfora.net"
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>"
else
Response.Write "Mail send failure. Error was " & Mailer.Response
end if
%>

If you are proficient enough to manipulate the code above, it is also possible to then add additional parameters to the mailing such as attachments, CCs, etc.

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

OR (if in subfolder)

Mailer.AddAttachment Server.MapPath("subfolder/somefile.doc")
Carbon Copies (CC)
Mailer.AddCC "Susan Smith", "susan.smith@domain.co.uk"
Blind Carbon Copies (BCC)
Mailer.AddBCC "John Smith", "john.smith@domain.co.uk"
Using a Text File for the Body of an E-Mail
Mailer.GetBodyTextFromFile Server.MapPath("welcomeMail.txt"), True,False

OR (if in subfolder)

Mailer.GetBodyTextFromFile Server.MapPath("subfolder/welcomeMail.txt"), True,False
For additional information, you may want to reference: