How to Send Email code in c#


  1. The following method sends mail to another user in C sharp
  2. Add Namespace File,


using System.Net;
using System.Net.Mail;


 Public void SendEmail(string Message, string EmailID)
        {
            try
            {
                MailMessage mail = new MailMessage();
                mail.From = new MailAddress("sudamtambe44@gmail.com");
                mail.To.Add(EmailID);
                mail.Subject = "Application Status";
                mail.Body = Message;

                SmtpClient smtp = new SmtpClient("smtp.office365.com", 587);
                smtp.EnableSsl = true;
                smtp.Credentials = new NetworkCredential("sudamtambe44@gmail.com", "abcd*88");
                smtp.Send(mail);
             
            }
            catch (SmtpException ex)
            {
                lblerror.Text = cnclss.SendExcepToDB(pageName, MethodBase.GetCurrentMethod().Name.ToString(), HttpContext.Current.Request.Url.ToString(), ex);
            }
        }

Comments

Popular posts from this blog

String Program in C#

CSV using XmlNode

Controller_Model. cs