Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Accessing SMTP Mail Settings from Web.Config File by using c#

Need to read my SMTP email settings defined under system.net section in my web.config file.

Below is one example of SMTP email setting defined in web.config file: (Under Section)

<system.net>
<mailSettings>
<smtp deliveryMethod="Network" from="[email protected]">
<network defaultCredentials="true" host="localhost" port="25" userName="user” password="testPassword"/>
</smtp>
</mailSettings>
</system.net>

How to Access the SMTP Mail Setting by using c#

like image 972
Gaurav Agrawal Avatar asked Jul 12 '11 09:07

Gaurav Agrawal


People also ask

How do I read email settings from web config?

Reading SMTP Mail Settings from Web.Config file in ASP.Net Then an object of the SmtpClient class is created and the settings of the Mail Server such has Host, Port, DefaultCredentials, EnableSsl, Username and Password are fetched from the mailSettings section of the Web.

What is System Net Mail?

Allows applications to send email by using the Simple Mail Transfer Protocol (SMTP). The SmtpClient type is obsolete on some platforms and not recommended on others; for more information, see the Remarks section.


1 Answers

Just use the System.Net.Mail classes to send your e-mails. It will automagically pick-up the Mail setting from your web.config.

like image 143
Edwin de Koning Avatar answered Sep 28 '22 08:09

Edwin de Koning