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