Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public ViewResult Index(MailModel objectMailModel)
- {
- if (ModelState.IsValid)
- {
- int count = 0;
- if (objectMailModel.To.Contains(";"))
- {
- string[] str = objectMailModel.To.ToString().Split(';');
- count = str.Length;
- for (int i = 0; i < count; i++)
- {
- MailMessage mail = new MailMessage();
- mail.To.Add(str[i]);
- mail.From = new MailAddress("hare.b@kencloud.co.in");
- mail.Subject = objectMailModel.Subject;
- mail.Body = objectMailModel.Body;
- mail.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient("smtp-mail.outlook.com");
- //smtp.Host = "smtp.gmail.com";
- smtp.Host = "smtp.live.com";
- smtp.Port = 587;
- smtp.Credentials = new System.Net.NetworkCredential("hare.b@kencloud.co.in", "***********");
- smtp.EnableSsl = true;
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.Send(mail);
- ViewBag.Message = "Sent";
- }
- return View("Index", objectMailModel);
- }
- else
- {
- MailMessage mail = new MailMessage();
- mail.To.Add(objectMailModel.To);
- mail.From = new MailAddress("hare.b@kencloud.co.in");
- mail.Subject = objectMailModel.Subject;
- mail.Body = objectMailModel.Body;
- mail.IsBodyHtml = true;
- SmtpClient smtp = new SmtpClient("smtp-mail.outlook.com");
- smtp.Host = "smtp.live.com";
- smtp.Port = 587;
- smtp.UseDefaultCredentials = true;
- smtp.Credentials = new System.Net.NetworkCredential("hare.b@kencloud.co.in", "***********");
- smtp.EnableSsl = true;
- smtp.DeliveryMethod = SmtpDeliveryMethod.Network;
- smtp.Send(mail);
- ViewBag.Message = "Sent";
- return View("Index", objectMailModel);
- }
- }
- else
- {
- return View();
- }
- }
Add Comment
Please, Sign In to add comment