Migrating a Web Server to IIS 5.0 |
IIS 5.0 includes a SMTP service and exposes all of its functionality through the Collaboration Data Objects (CDO) object model. When the SMTP service is installed and configured, you can use the CDONTS object included with IIS 5.0 to send an e-mail message from an ASP page, as shown in the following example, written in JScript:
<%@ LANGUAGE=JScript %>
<%
var msg;
msg = Server.CreateObject("CDONTS.NewMail");
msg.From = "someone@microsoft.com";
msg.To = "someone@microsoft.com";
msg.Subject = "Sample message";
msg.Body = "This is a sample message.";
msg.Send();
%>
or in VBScript:
<%@ LANGUAGE=VBScript %>
<%
Dim objMail
Set objMail = CreateObject("CDONTS.NewMail")
objMail.Send "someone@microsoft.com","someone@microsoft.com","Message subject","Message body"
%>
The following is an ASP page written in VBScript that illustrates how to capture the Http_Referer, Remote_User environment variables from a form and return the message, “Thank you User_Name for sending mail.”
<%@ LANGUAGE=VBScript %>
<%
'*** Load Constants
SENDTO = "someone@microsoft.com"
SUBJECT = "Form Reply-Response Example"
USERNAME = Request.ServerVariables("LOGON_USER")
'*** Post values to the form
name = Request.Form("name")
email = Request.Form("email")
telephone = Request.Form("telephone")
category = Request.Form("category")
'*** Build message body
BodyString = BodyString & "Name = " & name & VbCrLf
BodyString = BodyString & "Email = " & email & VbCrLf
BodyString = BodyString & "Telephone = " & telephone & VbCrLf
BodyString = BodyString & "category = " & category & VbCrLf
'***Begin Send mail to customer***
Set myMail =
Server.CreateObject("CDONTS.NewMail")
myMail.From = email
myMail.To = SENDTO
myMail.Subject = SUBJECT
myMail.Body = BodyString
myMail.Send
Set myMail = Nothing
'***End Send mail to customer***
'***Build confirmation body***
OutputString = "<P></BODY></HTML>"
OutputString = OutputString & "<P> <P>Thank you " & USERNAME & " for
sending mail<P>" & VbCrLf
'***Begin Build footer and send to customer***
OutputString = OutputString & "<P></BODY></HTML>"
Response.Write OutputString
'***End Build footer and send to customer***
%>
The following example, also in VBScript, shows how to send an e-mail attachment.
att_file="c:\Reports\wklyRpt.txt"
f_name="WklyRpt.txt"
Set objMail = CreateObject("CDONTS.NewMail")
objMail.From="someone@microsoft.com"
objMail.To="someone@microsoft.com"
objMail.Subject="Weekly Report"
objMail.Body="Attached below is my weekly report file."
objMail.AttachFile att_file,f_name
mailres=objMail.Send()