SIGN UP MEMBER LOGIN:    
ARTICLE

How to send mail from Gmail without login your Gmail account

Posted by Purushottam Rathore Articles | Learn .NET August 02, 2010
In this article I am going to discuss how to send mail from Gmail using Asp.net 3.5 without login your Gmail account.
Reader Level:

In this article I am going to discuss how to send mail from Gmail using Asp.net 3.5 without login your Gmail account.

Write the small line of code as follows:

Sample:

<html>
<body>
    <form id="form1" runat="server">
    <fieldset style="width: 500px; padding: 10px;">
        <legend>Sending email from GMail</legend>
        <div align="left" style="padding: 5px;">
            Your Gmail EmailID<br />
            <asp:TextBox ID="TextBoxSenderEmailId" runat="server" Width="250px"></asp:TextBox><font color=silver>Please enter your GMailId <br />(e.g yourId@gmail.com)</font><br />
<br />
            Friend's EmailId<br />
            <asp:TextBox ID="TextBoxReceiverEmailId" runat="server" Width="250px"></asp:TextBox><font color=silver>Please enter your friend's emailId<br />(e.g abc@xyz.com)</font><br />
            <br />
            Subject<br />
            <asp:TextBox ID="TextBoxSubject" runat="server" Width="350px"></asp:TextBox><br />
            <br />
            Body<br />
            <asp:TextBox ID="TextBoxBody" Width="350px" TextMode="MultiLine" Rows="5" runat="server"></asp:TextBox>
<br /><br />
            <asp:Button ID="btnSendEmail" runat="server" OnClick="btnSendEmail_Click" Text="Send" />
        </div>
    </fieldset>
    </form>
</body>
</html>

Img1.png

using System;

using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public
partial class SendingMailByGMail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
    }

    
protected void btnSendEmail_Click(object sender, EventArgs e)
    {
        System.Net.Mail.MailMessage MyMailMessage = new System.Net.Mail.MailMessage(TextBoxSenderEmailId.Text, TextBoxReceiverEmailId.Text, TextBoxSubject.Text, "");
        MyMailMessage.IsBodyHtml = false;
        MyMailMessage.Body = TextBoxBody.Text;
        //provide Authentication Details need to be passed when sending email from gmail
        System.Net.NetworkCredential mailAuthentication = new System.Net.NetworkCredential(TextBoxSenderEmailId.Text, "password");//Sender password

        //Smtp Mail server of Gmail is "smpt.gmail.com" and it uses port no. 587
        System.Net.Mail.SmtpClient mailClient = new System.Net.Mail.SmtpClient("smtp.gmail.com", 587);

        //Enable SSL

        mailClient.EnableSsl = true;
        mailClient.UseDefaultCredentials = false;
        mailClient.Credentials = mailAuthentication;
        mailClient.Send(MyMailMessage);
    }
}

Login to add your contents and source code to this article
share this article :
post comment
 

very useful and nice coding for me....

Posted by Maharaja Mca Jan 06, 2012

thank u so much for post this article.. but i got some error that is smptException was unhandled by user code( The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at) help me sir..

Posted by Sujitha Jul 27, 2011

Thanks Ishan :)

Posted by Purushottam Rathore May 18, 2011

nice article sir, i m big fan of u. ishan...

Posted by ishan singh May 17, 2011

I am somnath dey. please give me ur email ID. My email Id is dey.somnath.som@gmail.com

Posted by somnath dey May 12, 2011
Nevron Gauge for SharePoint
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Become a Sponsor