问题
I use the standard web.config 'mailSettings' as the backbone for my ASP.NET emails. However, I find it to being increasingly limited in capability. For example, I want to send emails from many different user accounts (support, sales, management etc.) and it doesn't seem like mailSettings supports this. Is there any way to avoid using mailSettings so that I can use multiple accounts? Any disadvantages (and if not, then why would anyone use mailSettings?)
<mailSettings>
<smtp from="support@company.com">
<network host="smtp.gmail.com" port="587" userName="support@company.com" password="abcPassword"/>
</smtp>
</mailSettings>
回答1:
If you're sending your mail using a System.Net.Mail.MailMessage, you should be able to override the From in the web.config by setting the MailMessage.From to a new MailAddress.
来源:https://stackoverflow.com/questions/4979182/sending-mail-with-asp-net