|
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> |