SmtpClient class not picking up default parameters from Web.Config file

 ̄綄美尐妖づ 提交于 2019-12-01 08:16:17

问题


config file :

<system.net>
<mailSettings>
<smtp from="YYYYY@xxxxxx.com">
<network
host="mail.xxxxxx.com"
port="25"
password="password"
userName="user@xxxxxx.com"
defaultCredentials="false"
/>
</smtp>
</mailSettings>
</system.net>

I've already tried defaultCredentials="true" but i recieved following message:

System.FormatException: Smtp server returned an invalid response.

how to fix the problem?


回答1:


Set the deliveryMethod property on the smtp element to 'network'.




回答2:


sorry, had the web.config from the Views folder in ASP.NET MVC open, not the one in the application root - DOH!!!!!

Working fine now :))




回答3:


Where have you placed these elements inside your web.config? They should look like this:

<configuration>
  <system.net>
    <mailSettings>
      <smtp from="YYYYY@xxxxxx.com">
        <network host="mail.xxxxxx.com" port="25" password="password" userName="user@xxxxxx.com" defaultCredentials="false"/>
      </smtp>
    </mailSettings>
  </system.net>
<configuration>

But based on the exception you're getting it sounds like the config is working but your message is improperly formatted. What does your MailMessage look like? What are you passing as your From, Email, Subject and Body?



来源:https://stackoverflow.com/questions/329411/smtpclient-class-not-picking-up-default-parameters-from-web-config-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!