This example shows how to send an email with ASP. This is possible
using CDO (Collaboration Data Objects), a COM library created to
send email via SMTP protocol. You can also use the more power JMail or ASPEmail components.
In order to run this example you must set the correct value for
"from" and "to" properties of
objCDO.
Here is a simple example,
' Create mail object
Set objMail = Server.CreateObject("CDO.Message")
with objMail
.From = strFromAddress
.To = strToAddress
.Subject = "Simple mail test"
.TextBody = "Hi there; this is a test from the web server."
.Send()
End With
Set objMail = Nothing
If you are on Windows 2000 server, you can use this version.
---------- SendMail.asp -------------------
<HTML>
<HEAD>
<title> Here is the code for sending an email using ASP </title>
</HEAD>
<BODY>
<%
' declare a CDO object
dim objCDO
' create a CDO object
set objCDO = Server.CreateObject("CDONTS.NewMail")
' set the properties
objCDO.From = "youraccount@yourdomainname"
objCDO.To = "anotheraccount@domainname"
objCDO.Subject = "mail test"
objCDO.Body = "Hello this is a Test"
' send the email
objCDO.Send
set objCDO = Nothing
response.write ("Message successfully sent.")
%>
</BODY>
</HTML>
If you want to use ASP .NET, here is a sample script:
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="System.Web.Mail" %>
Dim myMessage As New MailMessage
Dim myMail As SmtpMail
myMessage .From = "user@domain.com"
myMessage .To = "user@domain.com"
myMessage .Subject = "Test email message"
myMessage .Body = "Test of ASP.NET message"
myMail.SmtpServer = "mail.domain.com"
myMail.Send(myMessage)
|