Home Articles ASP.Net Sending Email Through Aspnet Using C#


Sending Email Through Aspnet Using C#

User Rating: / 4
PoorBest 
Avatar

The following Sample Code is the code which can be used to send mails through ASP.Net C#.... its a working code for me.....


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(" This e-mail address is being protected from spambots. You need JavaScript enabled to view it "," This e-mail address is being protected from spambots. You need JavaScript enabled to view it "," This e-mail address is being protected from spambots. You need JavaScript enabled to view it ","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(" This e-mail address is being protected from spambots. You need JavaScript enabled to view it ", "password");

smtpClient.Send(message);
msg = "Successful";
}
catch (Exception ex)
{
msg = ex.Message;
}
return msg;
}

}

 


For Details Visit Here
--
Thanks and Regards
Meetu Choudhary

 

Comments (3)
  • g_arora
    Good one :)

    Goodle search returned this link : http://www.dotnetspider.com/resources/21608-Sending-Email-Through-ASP- NET-using-C.aspx

    As per SEO I suggested when you post your article on multiple sites then change the title to recognize your individual sites
  • sankkrit  - Nice
    Nice post...

    Waiting some more...
  • g_arora
    Really nice but I do not like the formatting
Only registered users can write comments!
 

Member Login

AddThis Social Bookmark Button