0

I'm trying to get email working in my application. In my web.config I have:

<system.net>
    <mailSettings>
        <smtp from="myemail@email.com">
            <network host="A host address" port="37" />
        </smtp>
    </mailSettings>
</system.net>

Now in the code I new up a SmtpClient();

var client = new SmtpClient();

Then I have to go ahead and set the port and host?

client.Host = "A host address";
client.Port = 37;

I'm confused by this. I don't understand the point of setting them in the webconfig if when you new up a SmtpClient you have to go ahead and set the variables.

Am I missing something?

4

2 回答 2

0

我认为您只是缺少该deliveryMethod属性。将您的配置更改为:

<system.net>
  <mailSettings>
    <smtp from="myemail@email.com" deliveryMethod="Network">
      <network host="A host address" port="37" />
    </smtp>
  </mailSettings>
</system.net>
于 2013-05-07T23:20:44.437 回答
0

下面是如何在 web.config 中设置 system.net 的示例。

<system.net>
    <mailSettings>
      <smtp from="info@somedomain.com">            
        <network 
            host="smtp.sendgrid.com"
            port="587" 
            userName="stackoverflow"
            password="qwertyuiuioopp"
        />
      </smtp>
    </mailSettings>
</system.net>
于 2014-03-28T11:27:33.723 回答