Send email using Gmail in Asp.net C#: Here in this article, we demonstrate how to send an email using your Google, Gmail account in Asp.net c#. Sending Email is a common task of a web application for many purposes like- Error logging, Reporting, Newsletters as well as many other reasons.
Gmail is a good solution for this purpose. Gmail provides SMTP and POP access which can be utilized for sending and receiving E-mails.
Code to send email in asp.net c# with your Gmail google account:
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Web.Configuration;
using System.Net.Mail;
// system.net.mail namespace is used for emailing.
protected void btnsubmit_Click(object sender, ImageClickEventArgs e)
{
//Code for send Email
MailMessage sendMailforSA = new MailMessage();
SmtpClient smtpforSA = new SmtpClient();
string subjectforSA = null;
subjectforSA = "Thanks for apply";
System.Net.NetworkCredential credforSA = new System.Net.NetworkCredential("Superman@gmail.com", "password");
sendMailforSA.To.Add(txtemailid.Value);
MailAddress cc = new MailAddress("info@superman.com");
sendMailforSA.CC.Add(cc);
// sendMailforSA.CC("abcxxx@gmail.com");
sendMailforSA.From = new MailAddress("Rajnikant@gmail.com");
sendMailforSA.Subject = subjectforSA.ToString();
sendMailforSA.Body =" Thank you.... your message you can use html tag for style effect";
sendMailforSA.IsBodyHtml = true;
smtpforSA.Host = "smtp.gmail.com";
smtpforSA.Port = 25;
smtpforSA.EnableSsl = false;
smtpforSA.UseDefaultCredentials = false;
smtpforSA.Credentials = credforSA;
smtpforSA.Send(sendMailforSA);
}
Thank you for reading, pls keep visiting this blog and share this in your network. Also, I would love to hear your opinions down in the comments.
PS: If you found this content valuable and want to thank me? 👳 Buy Me a Coffee
Post Comment
Your email address will not be published. Required fields are marked *