The Below application is used to Describe How to send a mail from Gmail account using C# code.
The Source Code For This Application is :
using System;
usingSystem.Collections.Generic;
usingSystem.ComponentModel;
usingSystem.Data;
usingSystem.Drawing;
usingSystem.Linq;
usingSystem.Text;
usingSystem.Windows.Forms;
usingSystem.Net.Mail;
namespace SendEmail
{
public partial class Form1 : Form
{
publicForm1()
{
InitializeComponent();
}
privatevoid Form1_Load(objectsender, EventArgs e)
{
}
privatevoid button1_Click(objectsender, EventArgs e)
{
button1.Enabled = false;
try
{
MailMessagemail = new MailMessage();
SmtpClientSmtpServer = new SmtpClient("smtp.gmail.com");
mail.From = new MailAddress(txtFrm.Text);
mail.To.Add(txtTo.Text);
mail.Subject = txtSub.Text;
mail.Body = txtMsg.Text;
SmtpServer.Port = 25;
SmtpServer.Credentials = new System.Net.NetworkCredential(txtFrm.Text.ToString(),txtPsw.Text.ToString());
SmtpServer.EnableSsl = true;
SmtpServer.Send(mail);
MessageBox.Show("Mail Sent Successfull");
}
catch(Exception emsg)
{
MessageBox.Show("Mail Sending Failed..Due to" +emsg.Message.ToString());
}
txtFrm.Text = txtPsw.Text =txtSub.Text = txtMsg.Text = txtTo.Text = "";
button1.Enabled = true;
}
}
}
For downloading the Entire Solution File: CLICK HERE


