Send email in ASP.NET with Gmail Account using System.Net.Mail

No.of Views998
Bookmarked0 times
Downloads 
Votes0
By  jalpesh   On  30 Dec 2010 10:12:04
Tag : ASP.NET , Email
In this article, we will focus how to use the Gmail Account details to send email in asp.net with System.NET.Mail. The Email is a compulsory part of the web applications to send information to users or other way direction.
emailbookmarkadd commentsprint

Images in this article missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at info@codegain.com

 

Introduction

In this article, we will focus how to use the Gmail Account details to send email in asp.net with System.NET.Mail. The Email is a compulsory part of the web applications to send information to users or other way direction.

Like if there is shopping cart application for example then when a order created on the shopping cart you need to send an email to administrator of website for Order notification and for customer you need to send an email of receipt of order. So any web application is not complete without sending email. This post is also all about sending email. In post I will explain that how we can send emails from our Gmail Account without purchasing any smtp server etc.
There are some limitations for sending email from Gmail Account. Please note following things.
 

  1. Gmail will have fixed number of quota for sending emails per day. So you can not send more then that emails for the day.
  2. Your from email address always will be your account email address which you are using for sending email.
  3. You can not send an email to unlimited numbers of people. Gmail ant spamming policy will restrict this.
  4. Gmail provide both Popup and SMTP settings both should be active in your account where you testing. You can enable that via clicking on setting link in gmail account and go to Forwarding and POP/Imap.

So if you are using mail functionality for limited emails then Gmail is Best option. But if you are sending thousand of email daily then it will not be Good Idea.

Here is the code for sending mail from Gmail Account.

C# Code

using System.Net.Mail;
 
namespace Experiement
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender,System.EventArgs e)
        {
            MailMessage mailMessage = new MailMessage(new MailAddress("from@gmail.com")
                                       ,new MailAddress("to@yahoo.com"));
            mailMessage.Subject = "Sending mail through gmail account";
            mailMessage.IsBodyHtml = true;
            mailMessage.Body = "<B>Sending mail thorugh gmail from asp.net</B>";
 
            System.Net.NetworkCredential networkCredentials = new
            System.Net.NetworkCredential("yourgmailaddress@gmail.com", "yourpassword");
 
            SmtpClient smtpClient = new SmtpClient();
            smtpClient.EnableSsl = true;
            smtpClient.UseDefaultCredentials = false;
            smtpClient.Credentials = networkCredentials;
            smtpClient.Host = "smtp.gmail.com";
            smtpClient.Port = 587;
            smtpClient.Send(mailMessage);
 
            Response.Write("Mail Successfully sent");
 
        }
    }
}

That’s run this application and you will get like below in your account.

Output 

Image Loading

Conclusion

In this article,we have discussed,how to use the Gmail Account details to send email in asp.net with System.NET.Mail.hope like it.

 
Sign Up to vote for this article
 
About Author
 
jalpesh
Occupation-Software Engineer
Company-DotNetJaps
Member Type-Expert
Location-India
Joined date-08 May 2010
Home Page-http://www.dotnetjalps.com
Blog Page-http://www.dotnetjalps.com
I am jalpesh vadgamaa an Microsoft MVP for Visual C# and BrainBench Certified ASP.NET Developer having experience of five year in Microsoft .NET Technology.I am working as Project Leader in Mid Size company.My work area comprises of Enterprise Level projects using ASP.NET and other Microsoft .NET Technologies.Please feel free to contact me for any queries via posting comments on my blog I will try to reply as early as possible.
 
 
Other popularSectionarticles
    The Email is important in the web site. When you are create a new website you have to implement in the email sending features as well. So in this article I will explain how to send email using ASP.NET with SMTP.
    Published Date : 06/Dec/2010
    In this article, I going to explain that how to perform the validation for email address in HTML 5 using inbuilt features in it. In addition, the HTML 5 has many features those related with user input validations.
    Published Date : 27/Mar/2012
    With Microsoft.NET Framework 2.0 everything is asynchronous and we can send mail also asynchronously
    Published Date : 14/May/2010
    This lesson focuses on how to send mail messages in .NET Framework via a SMTP server. It firstly discusses the techniques which .NET Framework provides you to send mail messages. After that, it discusses types available for you when working with SMTP servers. Next, it discusses how to implement these techniques and to send mails from a .NET client. At the end of this lesson, there is a sample application, Geming Mail+, which is used to send mails from a various SMTP servers. This application
    Published Date : 16/Feb/2010
    Sending mails from gmail account using ASP.net
    Published Date : 15/Feb/2010
Comments
By:PraveenDate Of Posted:4/18/2011 12:12:54 PM
error
this gives an error... "Service not available, closing transmission channel. The server response was: Cannot connect to SMTP server 72.14.213.109 (72.14.213.109:25), connect error 10060" please help me on this error..... thanks
Leave a Reply
Title:
Display Name:
Email:
(not display in page for the security purphase)
Website:
Message:
Please refresh your screen using Ctrl+F5
If you can't read this number refresh your screen
Please input the anti-spam code that you can read in the image.
^ Scroll to Top