private static SmtpClient GetSmtpClient(User user) { try { var db = new WMTestDbContext(); var smtpServer = user.Config.Server; var smtpPort = user.Config.Port; var smtpUsername = user.Config.Username; var smtpPassword = user.Config.Password; var smtpSSL = user.Config.SSL; var basicCredential = new NetworkCredential(smtpUsername, smtpPassword); var smtpClient = new SmtpClient() { UseDefaultCredentials = !smtpSSL, Host = smtpServer, Port = smtpPort, EnableSsl = smtpSSL, Credentials = basicCredential }; return(smtpClient); } catch (Exception e) { throw new Exception("Error in SmtpClient Configuration - " + e.Message); } }
public static string SendEmailFromWebMaster(string recipient, string body, string subject) { var db = new WMTestDbContext(); var webMaster = db.Users.Include(x => x.Config).FirstOrDefault(x => x.UserName.Equals("chitestwebmaster")); var email = new Email() { Sender = webMaster, Recipient = recipient, Subject = subject, Body = body }; return(SendEmail(email, null)); }