how to configure smtp settings in web.config

前端 未结 3 1615
余生分开走
余生分开走 2020-12-03 09:54

I\'m trying to fix an email issue with an inherited website and don\'t have access to the code (i.e. just the compiled files). This site needs to be hosted on a new web serv

相关标签:
3条回答
  • 2020-12-03 10:25

    Set IIS to forward your mail to the remote server. The specifics vary greatly depending on the version of IIS. For IIS 7.5:

    1. Open IIS Manager
    2. Connect to your server if needed
    3. Select the server node; you should see an SMTP option on the right in the ASP.NET section
    4. Double-click the SMTP icon.
    5. Select the "Deliver e-mail to SMTP server" option and enter your server name, credentials, etc.
    0 讨论(0)
  • 2020-12-03 10:29

    I don't have enough rep to answer ClintEastwood, and the accepted answer is correct for the Web.config file. Adding this in for code difference.

    When your mailSettings are set on Web.config, you don't need to do anything other than new up your SmtpClient and .Send. It finds the connection itself without needing to be referenced. You would change your C# from this:

    SmtpClient smtpClient = new SmtpClient("smtp.sender.you", Convert.ToInt32(587));
    System.Net.NetworkCredential credentials = new System.Net.NetworkCredential("username", "password");
    smtpClient.Credentials = credentials;
    smtpClient.Send(msgMail);  
    

    To this:

    SmtpClient smtpClient = new SmtpClient();
    smtpClient.Send(msgMail);
    
    0 讨论(0)
  • 2020-12-03 10:32

    Web.Config file:

    <configuration>
     <system.net>
            <mailSettings>
                <smtp from="yourmail@gmail.com">
                    <network host="smtp.gmail.com" 
                     port="587" 
                     userName="yourmail@gmail.com" 
                     password="yourpassword" 
                     enableSsl="true"/>
                </smtp>
            </mailSettings>
    </system.net>
    </configuration>
    
    0 讨论(0)
提交回复
热议问题