Categories
Uncategorized

How to set SmtpClient properties using web.config

SmtpClient Class allows applications to send e-mail by using the Simple Mail Transfer Protocol (SMTP). Instead of assigning properties of this class in C# , we can use the <system.net> element in the web.config as shown below :

<system.net>
<mailSettings>
<smtp from = "email@abc.com">
<network
host = "mail.abc.com"
port = "25"
password = "password"
userName = "email@abc.com"
defaultCredentials = "false"
enableSsl = "true"
/>
</smtp>
</mailSettings>
</system.net>

The advantage of this approach is that we can change the mail settings without having to rebuild the entire application.

Hope this helps 🙂

Further Reading : 
Sending Email with System.Net.Mail