Flare Hosting
Home Products and Services About Us Support Resellers Contact Us Site Map Call Toll-Free: 1-877-97-FLARE (35273)
Support - FAQ
ASP and .NET FAQ - CDO Sample ASP and .NET script

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)



See also:

  Domain Search
www.  
  Special Offer
 Free Domain Registration
more info 
 Customer Referral Program
more info 
30day money back guarantee
Microsoft Certified Partners
  Copyright © 1999-2008 Flare Hosting. All Rights Reserved.
  Terms and Conditions of Use  |  Domain Registration Agreement  |  ICANN Policy  |  Guarantees