Sending Email with ASP.NET

To send a mail from ASP.Net ypu have to import System.Web.Mail namespace and you need to use MailMessage class.


<% @Page Language="C#" %>
<% @Import Namespace="System.Web.Mail" %>
<%
MailMessage msgMail = new MailMessage();

msgMail.To = "you@MyDomain.Com";
msgMail.Cc = "webmaster@MyDomain.Com";
msgMail.From = "me@MyDomain.Com";
msgMail.Subject = "Test Mail from ASP.Net";

msgMail.BodyFormat = MailFormat.Html;
string strBody = "<html><body><b>Hello World</b>" +
" <font color=\"red\">ASP.NET</font></body></html>";
msgMail.Body = strBody;

SmtpMail.Send(msgMail);

Response.Write("Email was queued to disk");
%>


Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: