code to how to send email in asp.net using c#

The following article is for sending an email in asp.net # using smtp server.

          
MailMessage mailMessage = new MailMessage();
mailMessage.To.Add(GmailId);
mailMessage.Subject = "Msg Subject";
mailMessage.IsBodyHtml = true;
 mailMessage.Body = "Msg Body";
mailMessage.From = new MailAddress("EMaiid");
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtpout.secureserver.net";
smtp.Port = 25; smtp.EnableSsl = false;
NetworkCredential authinfo = new NetworkCredential("Emailid", "Password");
smtp.UseDefaultCredentials = false;
smtp.Credentials = authinfo;  
try
{

         smtp.Send(mailMessage);

}  
catch (SmtpException ex)
{  

//catch here exception

}

NetworkCredential for this class we need to pass Email ID and Password, from that credentials mail will be send to the mail id specified in MailAddress.

No comments:

Post a Comment