none
Encrypting e-mail credetials RRS feed

  • Question

  • I am trying to do an application to check for a service and if the service is down to send an e-mail. I got the application working nicely, but I would like to encrypt the credentials and that's  where I am having problems. I stored the credentials on the config file and try some examples for encryption with no success. This is the code for sending the e-mail.

    public void servicestatus(string subject, string body)
            {
                try
                {
                   
                    
                    SmtpClient SmtpServer = new SmtpClient(ConfigurationManager.AppSettings["SMTP"], int.Parse(ConfigurationManager.AppSettings["port"]));
                    SmtpServer.EnableSsl = true;
                 SmtpServer.Credentials = new System.Net.NetworkCredential(ConfigurationManager.AppSettings["user"], ConfigurationManager.AppSettings["password"]);
                    MailMessage mail = new MailMessage(ConfigurationManager.AppSettings["email"], ConfigurationManager.AppSettings["to"], subject, body);
                    SmtpServer.Send(mail);
                
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message);
                }
            }

    Edit: I added  my App.config for better understanding of my code. 

    <?xml version="1.0" encoding="utf-8" ?>
    
    <configuration>
      <startup>
        <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
      </startup>
      <appSettings>
        <add key="email" value="e-mailfrom"/>
        <add key="SMTP" value="smtp.office365.com"/>
        <add key="port" value="587"/>
        <add key="to" value="destinationemail"/>
    
        <add key="user" value="office365User"/>
        <add key="password" value="password"/>
    
      </appSettings>
    
    </configuration>




    • Edited by EMURRAY01 Tuesday, April 5, 2016 2:05 AM
    Wednesday, March 30, 2016 9:48 PM

Answers

All replies