Ads by Lake Quincy Media
| Next Tip?
Home » Asp.net, CSharp

Sending Email Through ASP.NET using C#

11 June 2009 2,203 views One Comment
1 Star2 Stars3 Stars4 Stars5 Stars (2 votes, average: 2.50 out of 5)
Loading ... Loading ...

Sending Email Through ASP.NET using C#

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

<pre>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 &amp;&amp; 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;
}
}
To downlaod working version of files visit here</pre>


Thanks and Regards
Meetu Choudhary

Popularity: 100%

Post to Twitter Tweet This Post

Related posts:

  1. Sending emails from gmail server Some time we need to send mails to others from...
  2. Sending Mails with attachments using Gmail Tweet This Post...
  3. Empty Recycle Bin Empty the Recycle Bin Ths following code is used to...

Related posts brought to you by Yet Another Related Posts Plugin.

Ads by Lake Quincy Media

One Comment »

  • KonstantinMiller said:

    Hi! I like your srticle and I would like very much to read some more information on this issue. Will you post some more?

Leave your response!

You must be logged in to post a comment.

Get Adobe Flash playerPlugin by wpburn.com wordpress themes