Send Email System.Net.Mail , SMTP server – Asp.Net
Send Email through SMTP server ( Gmail )
E-mail is one of the most common and reliable methods of communication for both personal and business purposes.
One of the big improvements in the configuration and maintenance of ASP.NET Web sites for version 2.0 is the ability to define common settings such as connection strings and mail server in a structured section of the web.config file
C#.net Coding Part
First add below mentioned namespace in code
Now write this code in click event of button
protected void btn_OnClick(object sender, EventArgs e)
{
try
{
MailMessage mail = new MailMessage();
mail.IsBodyHtml = true;
mail.To.Add(txtEmail.Text);
mail.Subject = txtSubject.Text;
mail.Body = txtbody.Text;
// mail.Attachments.Add(new Attachment(Server.MapPath(”~/C:\1236.JPG”)));
// mail.Priority = MailPriority.High;
SmtpClient client = new SmtpClient();
client.EnableSsl = true; // For Gmail SSL must True
client.Send(mail);
}
catch (Exception exc)
{
Response.Write(exc.Message);
}
}
Web.config Setting
configuration>
appSettings/>
connectionStrings/>
system.web>
compilation debug=”true“>
compilation>
authentication mode=”Windows“/>
system.web>
system.net>
mailSettings>
smtp from=”[email protected]“>
network host=”smtp.gmail.net” port=”587” userName =”[email protected]”
password=”password” defaultCredentials=”false” />
smtp>
mailSettings>
system.net>
configuration>
Very helpful….
Thanks for this!
Leave your response!