specifying “To” address in SMTP mail settings in .NET

孤街醉人 提交于 2019-12-11 07:06:24

问题


Is it possible to set "To" address in SMTP mail settings just like "From" address? there is an attribute for "From", but not "To" address. basically I need to send an email to technical support whenever a specific exception (or any unhandled exception) happens in the application. I can add it to "appSettings", but wondering if I can specify it in SMTP settings itself, without having to read from "appSettings". thanks in advance

  <system.net>
    <mailSettings>
      <smtp deliveryMethod="network" from="ben@contoso.com">
        <network host="some server" defaultCredentials="true" />
      </smtp>
    </mailSettings>
  </system.net>

回答1:


No, you cannot specify the To property in the config file. You will need to set it programatically.




回答2:


Well, you'll have to set the TO, CC, BCC, Subject, Content and a few other fields when you're calling the SendMail() function from your code.

It wouldn't make sense to define one single TO address as the only thing it would ever do is send mail from ben@contoso.com to jill@contoso.com.



来源:https://stackoverflow.com/questions/4428938/specifying-to-address-in-smtp-mail-settings-in-net

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