问题
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