Search the Knowledgebase Browse by Category
      Home       Web Hosting       Web Hosting Guide       Sample Scripts (Windows)
   Using AspEmail in ASP and ASP.Net

There are many available asp mail components like persists software. The sample code for Persists AspEmail is as follows :

<%

strHost = "127.0.0.1"

If Request("Send") <> "" Then

Set Mail = Server.CreateObject("Persits.MailSender")
' enter valid SMTP host
Mail.Host = strHost

Mail.From = Request("From") ' From address
Mail.FromName = Request("FromName") ' optional
Mail.AddAddress Request("To")

' message subject
Mail.Subject = "Price List"
' message body
Mail.Body = Request("Body")

strErr = ""
bSuccess = False
' catch errors
On Error Resume Next
' send message
Mail.Send ' send message
If Err <> 0 Then ' error occurred
strErr = Err.Description
else
bSuccess = True
End If
End If
%>

If the body is in html format than use following keyword above :

Mail.IsHTML = True

To add an attachment append following sample code :

Mail.AddAddress Request("To")
' Attach two files in the same directory (any file type can be attached)
strPath = Server.MapPath(".")
Mail.AddAttachment strPath & "\ps_logo.gif"

A similar sample code in ASP.Net is as follows :

<%@ Import Namespace="System.Web" %>
<%@ Import Namespace="ASPEMAILLib" %>
<%@ Import Namespace="System.Reflection" %>


<script runat="server" LANGUAGE="C#">

void Page_Load(Object Source, EventArgs E)
{
// Change this to your own SMTP server
String strHost = "127.0.0.1";

txtHost.InnerHtml = strHost;

if( IsPostBack )
{
// MailSender object declaration
ASPEMAILLib.IMailSender objMail;
objMail = new ASPEMAILLib.MailSender();

objMail.Host = strHost;

objMail.From = txtFrom.Value; // From address
objMail.FromName = txtFromName.Value; // optional

// To address, 2nd argument optional
objMail.AddAddress(txtTo.Value, Missing.Value);

// message subject
objMail.Subject = txtSubject.Value;

// message body
objMail.Body = txtBody.Value;

try
{
objMail.Send(Missing.Value);
txtMsg.InnerHtml = "<font color=green>Success! Message sent to " + txtTo.Value + ".</font>";
}
catch(Exception e)
{
txtMsg.InnerHtml = "<font color=red>Error occurred: " + e.Message + "</font>";
}
}
}

</script>


Live Support

If you have any questions at all, please don't hesitate to contact us

+91.22.28663101, 66789456

To submit Support ticket, click here


     Related FAQs
Setting up feedback form using ASP
Using AspEmail in ASP and ASP.Net
Using CDO (Collaboration Data Objects)
Connecting to MsSQL using DSN (Windows)
Connecting to MsSQL using DSN-less connection (Windows only)
File upload using Asp and Asp.Net
MsSQL Server Connection Strings - ODBC, OLE DB