2

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="[email protected]">
    <network host="smtp.gmail.com" port="587" userName="[email protected]" password="abcPassword"/>
  </smtp>
</mailSettings>

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

4 Comments

There does not seem to be any way to specify a password with MailMessage, which is needed for my multiple accounts
You should be able to get around that issue by setting the credentials when you initialize a SmtpClient. Something like the following: SmtpClient.UseDefaultCredentials = false; SmtpClient.Credentials = new System.Net.NetworkCredential("username", "password")
Ah cool. So can I ask if this method is any different from using 'MailMessage'. For example, is there some sort of performance benefit I get by having MailMessage pre-configured and ready to use?
There shouldn't be a performance difference, just having the default settings in the web.config makes it easier to send emails with less code since you don't have to manually specify all settings in code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.