How to: Accessing config file mail settings programmatically

Source: Internet
Author: User

The. NET Framework 2.0 provides APIs for accessing settings in a configuration file. Here's how you access the mail settings of a Config File programmatically:

C #

  using  system. configuration;  using  system. web. configuration;  using  system. net. configuration; configuration configurationfile = webconfigurationmanager. openwebconfiguration ( "pathtoconfigfile" ); mailsettingssectiongroup mailsettings = configurationfile. getsectiongroup ( "system.net/mailsettings" )  as  mailsettingssectiongroup;  If  (mailsettings! =  null ) { int  Port = mailsettings. SMTP. network. port;  string  host = mailsettings. SMTP. network. host;  string  Password = mailsettings. SMTP. network. password;  string  username = mailsettings. SMTP. network. username ;}
 
VB. NET
 Imports System. Configuration Imports System. Web. Configuration Imports System. net. Configuration Dim Configurationfile As Configuration = webconfigurationmanager. openwebconfiguration ( "Pathtoconfigfile" ) Dim Mailsettings As Mailsettingssectiongroup = configurationfile. getsectiongroup ( "System.net/mailsettings" ) If   Not Mailsettings Is   Nothing   Then           Dim Port As   Integer = Mailsettings. SMTP. Network. Port Dim Host As   String = Mailsettings. SMTP. Network. Host Dim Password As   String = Mailsettings. SMTP. Network. Password Dim Username As   String = Mailsettings. SMTP. Network. Username End If
 
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.