I'm about to release a console application onto one of our servers to be run by the task scheduler on a daily basis. Based on certain conditions, the application will email selected users through Office 365. In order to email users, of course, I'll need to use the credentials for an email account.
Given that this is an internal application on one of our servers, is embedding the username and password in the code safe? If not, what is the best practice to securely get around this?
If it helps, this is my code for the email function (written in C#):
String userName = "my.email@organization.ca";
String password = "myPassword";
MailMessage msg = new MailMessage();
msg.To.Add(new MailAddress(user.getEmail()));
msg.From = new MailAddress(userName);
msg.Subject = "My Subject";
msg.Body = "My message";
msg.IsBodyHtml = true;
SmtpClient client = new SmtpClient();
client.Host = "mail.office365.com";
client.Credentials = new System.Net.NetworkCredential(userName, password);
client.Port = 587;
client.EnableSsl = true;
client.Send(msg);
Edit: I should add that only administrators have access to this specific server.