Windows Phone Developers

Saturday, February 6, 2010

How to send mail using Gmail in C#

How to send mail using .NET


Here is a simple code that sends mail from gmail account

I have used this code to get the details from contact page to my mail ID



The code uses System.Net Mail namespace






protected void btnSubmit_Click(object sender, EventArgs e)
{

try
{
string sFrom = "telanganadeccan@gmail.com";
string sTo = "info@rowsandcolumns.in";
string sMessage = txtComments.Text + "\n" + txtName.Text;
string sSubject = txtName.Text;
string sMail = txtEmail.Text;
MailAddress oMailfrom = new MailAddress(sFrom);
MailAddress oMailTo = new MailAddress( sTo);
MailMessage message = new MailMessage(oMailfrom, oMailTo );
message.Body = "From " + sSubject + "\n Mail ID " + sMail + "\n Comments :\n" + sMessage;
SmtpClient client = new SmtpClient();
client.Timeout = 20000;
message.Subject = sSubject;
client.EnableSsl = true;
client.Send(message );

Response.Redirect ("~/Thanks.aspx");
}
catch (Exception ex)
{

Response.Redirect("~/Thanks.aspx");
}
}
}

Digg Technorati Delicious StumbleUpon Reddit BlinkList Furl Mixx Facebook Google Bookmark Yahoo
ma.gnolia squidoo newsvine live netscape tailrank mister-wong blogmarks slashdot spurl StumbleUpon

1 comment:

  1. if i run this it asks smtp host name... how to solve that?

    ReplyDelete