Sending mails from gmail account using ASP.net

No.of Views1332
Bookmarked0 times
Downloads 
Votes0
By  samee   On  15 Feb 2010 22:02:01
Tag : ASP.NET , Email
Sending mails from gmail account using ASP.net
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

 

Abstract:

We can communicate information to someone or a group of people in an easy an inexpensive way through e-mail. Sometime you may need to send a mail using gmail account from you information system. This article will show you how to send e-mail using gmail’s smtp server in ASP.Net application.

Technologies:

ASP.NET

Language:

C#.net

Prerequisite:

Visual studio 2005/2008

First open Visual studio 2008 or 2005 and create new web project called “sendEmailUsingGmail”.

newproject

Now click ‘OK’ button. Now you have to create the form which you need to send the mail. Add following code for the default.aspx.

{codecitation class="brush: html; gutter: true;" width="500px"}









Sending mails from gmail account using ASP.neth3>















From Gmail address : td>

asp:TextBox>td>

tr>

Your Gmail Password : td>


TextMode="Password" Width="200px">asp:TextBox> td>

tr>

To : td>


Width="200px">asp:TextBox> td>

tr>

Subject : td>


Width="200px">asp:TextBox> td>

tr>

Message : td>


TextMode="MultiLine" Height="100px"

Width="300px">asp:TextBox> td>

tr>

td>

tr>

div>

form>

body>


{/codecitation}

Now write the following code under btnemail_Click event.

{codecitation class="brush: csharp; gutter: true;" width="500px"}

protected void btnemail_Click(object sender, EventArgs e)

{

MailMessage mail = new MailMessage();

mail.To.Add(txtMailToAddress.Text);

mail.From = new MailAddress(txtFromGmailId.Text);

mail.Subject = txtSubject.Text;

mail.Body = txtBody.Text;

mail.IsBodyHtml = true;

SmtpClient smtp = new SmtpClient();

smtp.Host = "smtp.gmail.com";

smtp.Credentials = new System.Net.NetworkCredential

(txtFromGmailId.Text, txtgmailPassword.Text);

smtp.EnableSsl = true;

smtp.Send(mail);

}


{/codecitation}

Now compile the project and run the application. You will see the output like below.

output


{myadv_here}


Once you fill relevant details and click the ‘Send e-mail’ button, email will sent using gmail account through your ASP.Net application. You can realize with few lines you done it very easily.

Conclusion:

In this article we learned how Sending mails from gmail account using ASP.net. I hope this article assisted you.

Thank you
Sameetha
 
Sign Up to vote for this article
 
About Author
 
samee
Occupation-
Company-
Member Type-Fresh
Location-Singapore
Joined date-12 May 2009
Home Page-
Blog Page-
 
 
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
    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.
    Published Date : 30/Dec/2010
    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
Comments
There is no comments for this articles.
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