C# SendEmail using SMTP


  public class ContactUSDetails
    {
        public string fullname { get; set; }
        public string useremail { get; set; }
        public string mobile { get; set; }
        public string subname { get; set; }
        public string org_name { get; set; }
        public string yourmessage { get; set; }
    }
  
 public class SendEmailController : Controller
    {
        [HttpPost]
        public void Send(ContactUSDetails contactDetails)
        {
            try
            {
                string strFromAddress = WebConfigurationManager.AppSettings["fromAddress"];
                string strPassword = WebConfigurationManager.AppSettings["password"];
                var fullname = Convert.ToString( contactDetails.fullname);
                Random random = new Random();
                var complain = random.Next(1000, 99999);
                var mobile = Convert.ToString( contactDetails.mobile);
                var org = Convert.ToString(contactDetails.org_name);
                string strToAddress = Convert.ToString(contactDetails.useremail);
                var subject = " Grievance helpdesk, Complaint No.SSC_" + complain;
                var body = "Dear " + fullname +
                    ",<br><br>We received your complaint SSC_" + complain +
                    " and our grievance redressal team is now looking into the issue. Thank you for bringing this matter to our attention." + "<br><br>Best Regards,<br>Team Code-download.com";
                MailMessage mm = new MailMessage(strFromAddress, strToAddress)
                {
                    Subject = subject,
                    IsBodyHtml = true,
                    Body = body
                };
                SmtpClient smtp = new SmtpClient
                {
                    Host = "smtp.gmail.com",
                    Port = 587,
                    EnableSsl = true,
                    Credentials = new NetworkCredential(strFromAddress, strPassword)
                };
                    smtp.Send(mm);
            catch (Exception ex)   {  }        }

Comments

Popular posts from this blog

What is Aws?

Introduction to Agile development