public static bool SendMailThruGmail(Email email) { try { MailAddress fromAddress = new MailAddress(email.mailFrom); MailAddress toAddress = new MailAddress(email.mailTo); string subject = email.mailSubject; string body = email.mailBody; System.Net.Mail.MailMessage msg = new System.Net.Mail.MailMessage(fromAddress.Address, toAddress.Address, subject, body); msg.IsBodyHtml = true; var client = new SmtpClient("smtp.gmail.com", 587) { Credentials = new NetworkCredential("*****@*****.**", "bains@awan"), EnableSsl = true }; client.Send(msg); return true; } catch (Exception ex) { Console.WriteLine(ex.ToString()); return false; } }
public ActionResult Index(string name, string email, string message) { Email objEmail = new Email(); objEmail.mailTo = email; objEmail.mailBody = message; objEmail.mailSubject = "Help"; objEmail.mailFrom = this.repository.GetUserEmail(_userStatistics.UserId); Utilities.SendMailThruGmail(objEmail); TempData["IsEmailSent"] = "Mail successfully sent."; return View("Index"); }
public static void SendMailsToQueue(Email[] emails, string queuePath) { if (emails.Count() != 0) { var EmailQueue = new MessageQueueSender(queuePath); foreach (Email email in emails) { EmailQueue.SendMessage(email); } } }
private void StartEmailHandler() { string queuePath = ".\\private$\\EMAILQUEUE"; Email email = new Email() { mailTo = "*****@*****.**", mailFrom = "*****@*****.**", mailSubject = "QueueMail", mailBody = "Test MAil" }; //Utilities.SendMailThruGmail(email); //Utilities.SendMailToQueue(email, queuePath); //var reciver = new QueueListener(queuePath); //reciver.Start(); }
public static void SendMailToQueue(Email email, string queuePath) { if (email != null) { var EmailQueue = new MessageQueueSender(queuePath); EmailQueue.SendMessage(email); } }