public HomeController(AutoQuestraderContext db, IOptions <AppSettings> appSettings, IHubContext <TraderHub> traderHub) { this.db = db; this.appSettings = appSettings.Value; this.traderHub = traderHub; }
public static void SendEmail(string subject, string body, MailAddress toAddress, AutoQuestraderContext db) { try { if (string.IsNullOrEmpty(UserEmailPassword)) { Console.WriteLine("Please enter the password for: " + GetAccountOwnerEmail(db).Address); Console.WriteLine("(You should read the source code to be assured that your password is not used nefariously.)"); while (true) { var key = Console.ReadKey(true); if (key.Key == ConsoleKey.Enter) { break; } UserEmailPassword += key.KeyChar; } } var smtp = new SmtpClient { Host = "smtp.gmail.com", Port = 587, EnableSsl = true, DeliveryMethod = SmtpDeliveryMethod.Network, UseDefaultCredentials = false, Credentials = new NetworkCredential(GetAccountOwnerEmail(db).Address, UserEmailPassword) }; using (var message = new MailMessage(GetAccountOwnerEmail(db), toAddress) { Subject = subject, Body = body }) { smtp.Send(message); } } catch { Console.WriteLine("Error sending email. Make use the credentials are correct. If using gmail you may need to allow this app: https://support.google.com/accounts/answer/6010255?hl=en-GB"); SendEmail(subject, body, toAddress, db); } }
public TraderHub(AutoQuestraderContext db, IOptions <AppSettings> appSettings) { this.db = db; this.appSettings = appSettings.Value; }