public IHttpActionResult Send(string email, string message) { try { //var config = GetMailConfig(email, name, message); var config = new MailSenderConfiguration { Body = message, EnableSsl = true, From = "*****@*****.**", Host = "smtp.gmail.com", Password = "******", Port = 587, Subject = email, UseDefaultCredentials = false }; _mailSender.SendEmail(config); return Ok(); } catch (Exception ex) { return InternalServerError(ex); } }
public void SendEmail(MailSenderConfiguration config) { var mail = new MailMessage {From = new MailAddress(config.From)}; var smtp = new SmtpClient { Port = config.Port, EnableSsl = true, UseDefaultCredentials = false, Host = config.Host, DeliveryMethod = SmtpDeliveryMethod.Network }; mail.To.Add(new MailAddress("*****@*****.**")); mail.Subject = config.Subject; mail.Body = config.Body; smtp.Credentials = new NetworkCredential(config.From, config.Password); smtp.Send(mail); }