dotnetspider.com
Login Login    Register      

TutorialsForumCareer DevelopmentResourcesReviewsJobsInterviewCommunitiesProjectsTraining

Subscribe to Subscribers
Talk to Webmaster
Tony John

Facebook
Google+
Twitter
LinkedIn
Online Membersbaskar
Phagu Mahato
More...
Join our online Google+ community for Bloggers, Content Writers and Webmasters




Resources » .NET programming » ASP.NET/Web Applications

Send Email from your Gmail Account using ASP.NET


Posted Date:     Category: ASP.NET/Web Applications    
Author: Member Level: Diamond    Points: 70


In this article I have explained how to send email using ASP.NET with your GMAIL account. We can use system.net.mail and smtp pop server for sending email using asp.net. This article help you to configure your code and some userful settings.



 


How to send Email from your Gmail Account using ASP.NET


introduction
Many times I have seen on our dotnetspider website users put their question related to email sending using ASP.NET. This is a small attempt to help all developers who unaware of email sending using ASP.NET

Things Required before building code to send emails


We should keep all mandatory tools in our toolbox before building code, here is list of required things

1. Receiver Email address
2. Sender Email: UserID and Password
3. Namespace System.Net.Mail
4. Email Attachment if any
5. Last but not least you should keep enable your mail for POP settings in your Gmail account, following screen shot will clear idea.

POP



Getting started
After collecting all required tool let's starts with the website creation

1. create a website in visual studio
new_website



----------------------------------------------


2. Design form as per requirement, i have design a simple form here you can check

design_form



----------------------------------------------

3. put following code in your code behind, on send email click in TRY...CATCH block



MailMessage mail = new MailMessage();

//put mail from Email
mail.From = new MailAddress("MailFrom@gmail.com");

//put mail to Email
mail.To.Add(new MailAddress("MailTo@gmail.com"));


//you can add blank carbon copy mails here
//mail.Bcc.Add(new MailAddress("YOUR BCC EMAIL"));

//Get an attachment in attachment variable class
Attachment att = new Attachment("D:\\test.txt");

//add attachment to email
mail.Attachments.Add(att);

//Put email subject
mail.Subject = "Send Email with Gmail using ASP.NET";


//Put email body
string Body = "Put your Email Body TEXT here";

// Here you can put HTML string if you want email to be sent in HTML format.
mail.Body = Body;
mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();
smtp.Credentials = new System.Net.NetworkCredential("abc@gmail.com", "PASSWORD");

//keep ssl true if you have to send email with secured socket layer
smtp.EnableSsl = false;

smtp.Send(mail);


----------------------------------------------

code



now your code is ready to send email using ASP.NET

Exception points
There are so many factor that may affects your email sending code, here is list,

1. Firewall block port 587 (This is port for smtp gmail server)

2. Internet connection is not available on machine or internet connection has face some obstacles while pinging

3. Due to some typo mistake UserName and password may be get wrong

4. Enable SSL is block email sending

5. POP settings for smtp server in your Gmail account is disabled





Did you like this resource? Share it with your friends and show your love!


Responses to "Send Email from your Gmail Account using ASP.NET"
Author: mausumi    30 May 2012Member Level: Gold   Points : 0
hi

Thanks 4 this article.
it is helpful .



from
mausumi



Guest Author: samad     06 Jun 2012
not send.

1. Firewall block port 587 (This is port for smtp gmail server)???

4. Enable SSL is block email sending???



Feedbacks      

Post Comment:




  • 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:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)



    Type the numbers and letters shown on the left.


    Next Resource: Trend line for Line chart in SSRS 2005
    Previous Resource: How to integrate ASP.NET with Paypal
    Return to Resources
    Post New Resource
    Category: ASP.NET/Web Applications


    Post resources and earn money!
     
    More Resources
    Popular Tags   Tag posting guidelines   Search Tags  
    Email sending using asp.net  .  



    Follow us on Twitter: https://twitter.com/dotnetspider

    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Email subscription
  • .NET Jobs
  • .NET Articles
  • .NET Forums
  • Articles Rss Feeds
    Forum Rss Feeds


    About Us    Contact Us    Copyright    Privacy Policy    Terms Of Use    Revenue Sharing sites   Advertise   Talk to Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India
    2005 - 2012 All Rights Reserved.
    .NET and other trademarks mentioned in this site belong to Microsoft and other respective trademark owners.
    Articles, tutorials and all other content offered here is for educational purpose only.
    We are not associated with Microsoft or its partners.