Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

INTRODUCTION: Sending emails requires SMTP server and hence usually you won’t be able to send emails from your local machine [In case you have SMTP server configured on your local machine, you can surely send emails using that!].

The other way out would be to use a third parties SMTP server to send Emails.

 

In this Article I am going to use Gmail’s SMTP to send Emails.

 

Using System.Net.Mail; //Include This NameSpace


MailMessage MyMailMessage = new MailMessage();

MyMailMessage.From = new MailAddress("cadbuaryguy@gmail.com");

MyMailMessage.To.Add("learninggeeks@yahoo.com");

MyMailMessage.Subject = "Feedback Form";

MyMailMessage.IsBodyHtml = true;

MyMailMessage.Body = "<table><tr><td>" + txtName.Text + txtEmail.Text + txtComments.Text + "</table></tr></td>";

SmtpClient SMTPServer = new SmtpClient("smtp.gmail.com");

SMTPServer.Port = 587;

SMTPServer.Credentials = new System.Net.NetworkCredential("cadbuaryguy@gmail.com", System.Configuration.ConfigurationSettings.AppSettings["pwd"].ToString());

SMTPServer.EnableSsl = true;

try

{

SMTPServer.Send(MyMailMessage);

Response.Redirect("Thankyou.aspx");

}

catch (Exception ex)

{



}

Published Monday, October 05, 2009 12:18 PM by nijhawan.saurabh

Comments

# re: Sending SMTP Mail Using Gmail (using System.Net.Mail namespace)

Monday, October 05, 2009 10:14 PM by 凡客优惠券

The other way out would be to use a third parties SMTP server to send Emails.

# Twitter Trackbacks for Sending SMTP Mail Using Gmail (using System.Net.Mail namespace) - SaurabhNijhawan [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 Sending SMTP Mail Using Gmail (using System.Net.Mail namespace) - SaurabhNijhawan         [asp.net]        on Topsy.com

# re: Sending SMTP Mail Using Gmail (using System.Net.Mail namespace)

Tuesday, October 06, 2009 6:05 AM by markvt

Why didn't you put all config in web.config ?

# re: Sending SMTP Mail Using Gmail (using System.Net.Mail namespace)

Tuesday, October 06, 2009 7:23 AM by nijhawan.saurabh

Well i stored the password field in web.config for security.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Sunday, February 21, 2010 2:01 AM by wdnisha

i want to send my form data into my server email id .pls guide me. i have a form in my website .when user fill the form all the content of the form is send to my server email id in which i host my site

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Tuesday, May 31, 2011 2:34 PM by Ankit

I ame using same code but it give me error "Failure sending mail" it working on localhost but not working when i put on server..

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Thursday, July 14, 2011 5:32 PM by Raju Makwana

Hi

Its Great...!

Work Perfectly...Done.

Use it & Enjoy...!

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Monday, April 09, 2012 8:53 AM by nijith

Great working fine for me! thank a lot!!!

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Monday, April 16, 2012 6:21 AM by nijhawan.saurabh

wc Nijith!

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Saturday, January 12, 2013 7:25 PM by Naquin

I couldn’t refrain from commenting. Perfectly written.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Monday, January 14, 2013 3:30 PM by Hollenbeck

Hi there Dear, are you actually visiting this website on

a regular basis, if so afterward you will without doubt obtain

good know-how.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Friday, February 08, 2013 9:23 AM by Guerin

I have been exploring for a little for any high quality articles

or weblog posts on this sort of space . Exploring in Yahoo I

ultimately stumbled upon this site. Studying this information So i am satisfied to

exhibit that I've a very good uncanny feeling I came upon just what I needed. I such a lot surely will make certain to don?t fail to remember this site and provides it a glance regularly.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Sunday, February 10, 2013 10:09 AM by Vidal

obviously like your web-site however you need to check the spelling on several of your posts.

A number of them are rife with spelling problems and I in finding it very troublesome to tell the truth on the other hand

I'll certainly come again again.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Thursday, February 14, 2013 10:18 AM by Augustine

Admiring the time and energy you put into your blog and detailed information you present.

It's great to come across a blog every once in a while that isn't the same outdated rehashed material.

Great read! I've bookmarked your site and I'm adding your RSS feeds to my Google account.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Thursday, February 14, 2013 1:12 PM by Thorp

Good day! Do you use Twitter? I'd like to follow you if that would be ok. I'm

undoubtedly enjoying your blog and look forward to new updates.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Friday, February 15, 2013 10:03 AM by Simpson

great put up, very informative. I ponder why the opposite experts of this sector don't understand this. You should continue your writing. I'm confident, you've a great readers' base already!

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Saturday, February 16, 2013 7:19 AM by Chilton

Its like you read my mind! You seem to know a lot about this, like you wrote the book in it or something.

I think that you could do with a few pics to drive the message home a little bit, but other than that,

this is wonderful blog. A fantastic read. I will certainly be back.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Monday, February 18, 2013 9:11 AM by Simone

I really like your blog.. very nice colors & theme. Did you design this website yourself or did you hire someone to do it for you?

Plz respond as I'm looking to construct my own blog and would like to find out where u got this from. appreciate it

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Tuesday, March 05, 2013 12:26 AM by Mayo

Your way of explaining everything in this paragraph is in fact nice, all be able to simply be aware of it, Thanks a lot.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Sunday, April 07, 2013 2:13 PM by Crouch

Hello, yeah this post is in fact good and I have learned lot of things from it on the topic of blogging.

thanks.

# Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace) - Saurabh Nijhawan

Saturday, April 13, 2013 3:58 AM by Indian Tweet Bookmarking

saurabh nijhawan saurabhnijhawan nijhawansaurabh is a Sr. Software Developer in ASP.NET technologies

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Sunday, April 14, 2013 5:45 AM by Robison

Hey There. I found your blog using msn. This is a very well

written article. I will make sure to bookmark it and come

back to read more of your useful info. Thanks for the post.

I'll certainly return.

# re: Sending HTML Mail Using Gmail SMTP (using System.Net.Mail namespace)

Friday, April 19, 2013 12:23 PM by Strange

Heya are using Wordpress for your site platform?

I'm new to the blog world but I'm trying to get started and set up my own.

Do you need any coding expertise to make your own blog?

Any help would be really appreciated!

Leave a Comment

(required) 
(required) 
(optional)
(required)