Code to Send Email in ASP.Net

SEND EMAIL IN ASP.NET



Description



This code is use to send email via ASP.Net Page.
Generally it should be required to send the information like Login status,
update status or any updations to the user. This purpose you can use this code.


Below is the code to send mail in asp.net


Try
Dim mail As New MailMessage()

mail.[To] = "Receivers ID"
mail.From = "Sender ID"

mail.Subject = "Test Mail"
mail.BodyFormat = MailFormat.Html
mail.Body = (("<html><body>Dear ") + "Hi" & " </b> <br><br>") + " <br><br> <font color=orange>Click on the below link to be a part of DotNetSpider.</font><br><a href=http://www.dotnetspider.com?ref=jadhav_nilkumar=>Download Order</a><br><br><b> Do not Reply to this e-mail.</b><br><br>Thanks <br></body></html>"

SmtpMail.Send(mail)

Response.Write("SendMail")
Catch ex As Exception
Response.Write(ex.Message.ToString())
End Try




Thanks
Nilesh Jadhav


Comments

Author: ABitSmart30 Nov 2009 Member Level: Gold   Points : 0

Please format your resource.

Author: mithun29 Dec 2009 Member Level: Bronze   Points : 2

MailMessage mail = new MailMessage();
mail.From = FromAddress;
mail.To = ToAddress;
mail.Cc = CcAddress;

mail.Subject = Subject.ToString().Trim();

StringBuilder sbMailContent = new StringBuilder();
sbMailContent.Append(MailBody + "
");

mail.Body = "" + "" + sbMailContent + "" + "";

mail.BodyFormat = MailFormat.Html;

//SmtpMail.SmtpServer = server name

mail.Fields.Clear();
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpserverport", 25);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", server username);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", server password]);
mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout", 120);

SmtpMail.Send(mail);

Author: Er. Ram Singh06 Sep 2010 Member Level: Gold   Points : 2

using System;using System.Data;using System.Configuration;using System.Collections;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Net.Mail;public partial class Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { } protected void Button1_Click(object sender, EventArgs e) {//Calling the function SendMail Response.Write( SendMail("meetuchoudhary@gmail.com","meetudmeet@gmail.com","meetudmeet@yahoo.com","Test Mail","Test Mail Body")); } public string SendMail(string toList, string from, string ccList, string subject, string body) { MailMessage message = new MailMessage(); SmtpClient smtpClient = new SmtpClient(); string msg = string.Empty; try { MailAddress fromAddress = new MailAddress(from); message.From = fromAddress; message.To.Add(toList); if (ccList != null && ccList != string.Empty) message.CC.Add(ccList); message.Subject = subject; message.IsBodyHtml = true; message.Body = body; smtpClient.Host = "mail.server.com"; smtpClient.Port = 25; smtpClient.UseDefaultCredentials = true; smtpClient.Credentials = new System.Net.NetworkCredential("info@server.com", "password"); smtpClient.Send(message); msg = "Successful"; } catch (Exception ex) { msg = ex.Message; } return msg; }}



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