1

Is there a way to hide the password using SmtpClient object?

I would like avoid to hard-code my password in a class or in the web.config.

using (var smtp = new SmtpClient())
{
    var credential = new NetworkCredential
    {
        UserName = "user@outlook.com",  // replace with valid value
        Password = "password"  // replace with valid value
    };
    smtp.Credentials = credential;
    smtp.Host = "smtp-mail.outlook.com";
    smtp.Port = 587;
    smtp.EnableSsl = true;
    await smtp.SendMailAsync(message);
    return RedirectToAction("Sent");
}
Behzad
  • 3,502
  • 4
  • 36
  • 63
D.B
  • 4,009
  • 14
  • 46
  • 83

0 Answers0