1
Vote

Do not default SmtpServer to "127.0.0.1" in EmailTraceListenerData

description

This is a behavior change from the previous version. The better choice (the old way) is to pick the SMTP Server information from the configuration file setting under:

<system.net><mailSettings><smtp>

We want to share the SMTP settings across the application.


Here are the changes we need:
In EmailTraceListenerData.cs, remove Default value for SmtpServer:
     [ConfigurationProperty(smtpServerProperty)]   //changed.
    [ResourceDescription(typeof(DesignResources), "EmailTraceListenerDataSmtpServerDescription")]
    [ResourceDisplayName(typeof(DesignResources), "EmailTraceListenerDataSmtpServerDisplayName")]
    public string SmtpServer
    {
        get { return (string)base[smtpServerProperty]; }
        set { base[smtpServerProperty] = value; }
    }
In EmailMessage.cs:
    public virtual void SendMessage(MailMessage message)
    {
        var smtpClient = string.IsNullOrEmpty(configurationData.SmtpServer)? new SmtpClient() : new SmtpClient(configurationData.SmtpServer, configurationData.SmtpPort); //changed.

        SetCredentials(smtpClient);
        smtpClient.EnableSsl = configurationData.UseSSL;
        smtpClient.Send(message);
    }
In EmailTraceListener.cs, remove the following:
       //Guard.ArgumentNotNullOrEmpty(smtpServer, "smtpServer");

comments