choosing which domain account to use for sending email

给你一囗甜甜゛ 提交于 2019-12-12 05:43:08

问题


I have code for sending email to clients.

System.Net.Mail.SmtpClient Client = new System.Net.Mail.SmtpClient();
MailMessage Message = new MailMessage("From", "To", "Subject", "Body");
Client.Send(Message);

With following in App.config.

 <system.net>
    <mailSettings>
      <smtp from="support@MyDomain1.com">
        <network host="smtp.MyDomain1.com" port="111" userName="abc" password="helloPassword1" />
      </smtp>
    </mailSettings>
    <mailSettings>
      <smtp from="support@MyDomain2.com">
        <network host="smtp.MyDomain2.com" port="222" userName="xyz" password="helloPassword2" />
      </smtp>
    </mailSettings>
  </system.net>

Problem is that in my code how can I differentiate which mailsetting to use for a given mail, meaning when I want to send mail from MyDomain1 account vs MyDomain2 account


回答1:


There's one thread that contains the explanation how to achieve this.

Setting multiple SMTP settings in web.config?

Wanted originally to post it as an answer, but the system automatically converted it into a comment. Seems I have to write longer messages.

Glad it helped :)



来源:https://stackoverflow.com/questions/9891663/choosing-which-domain-account-to-use-for-sending-email

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