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 = "firstname.lastname@example.org"> <network host = "mail.abc.com" port = "25" password = "password" userName = "email@example.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