choosing which domain account to use for sending e

2019-09-09 10:36发布

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条回答
Fickle 薄情
2楼-- · 2019-09-09 11:32

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 :)

查看更多
登录 后发表回答