DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 17 Aug 2007 22:10:00 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    David Thielen am
          2    Manish Bafna
                 3    David Thielen am


How do I get the SMTP email address from web.config?   
I've tried:
MailSettingsSectionGroup mailConfig = 
WebConfigurationManager.GetSection("system.net/mailSettings") as 
MailSettingsSectionGroup;

and:
	Configuration configurationFile = 
WebConfigurationManager.OpenWebConfiguration("/Web.Config");
	MailSettingsSectionGroup mailConfig;
	if (configurationFile != null)
		mailConfig = configurationFile.GetSectionGroup("system.net/mailSettings") 
as MailSettingsSectionGroup;

The first method returns null and the second returns an object but it does 
not have the host or from properties set.

-- 
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
Date:Fri, 17 Aug 2007 22:10:00 -0700   Author:  

RE: How do I get the SMTP email address from web.config?   
Hi,
First write below code in web.config  </system.web> and before 
</configuration>:
<system.net >
    <mailSettings >
    <smtp from="who@myhost.com">
      <network host="mail.myhost.net" userName="xxxxx" password="xxxx"/>
    </smtp>
  </mailSettings>
    </system.net >

Then try this code:
Configuration configurationFile = 
WebConfigurationManager.OpenWebConfiguration("~\\Web.config");
        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;

            lblHost.Text = host;
            lblUserName.Text = username;
            lblPassword.Text = password;
        }
Also include following namespaces:
using System.Configuration;
using System.Web.Configuration;
using System.Net.Configuration;
-- 
Hope this helps.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



"David Thielen" wrote:


> I've tried:
> MailSettingsSectionGroup mailConfig = 
> WebConfigurationManager.GetSection("system.net/mailSettings") as 
> MailSettingsSectionGroup;
> 
> and:
> 	Configuration configurationFile = 
> WebConfigurationManager.OpenWebConfiguration("/Web.Config");
> 	MailSettingsSectionGroup mailConfig;
> 	if (configurationFile != null)
> 		mailConfig = configurationFile.GetSectionGroup("system.net/mailSettings") 
> as MailSettingsSectionGroup;
> 
> The first method returns null and the second returns an object but it does 
> not have the host or from properties set.
> 
> -- 
> thanks - dave
> david_at_windward_dot_net
> http://www.windwardreports.com
> 
> Cubicle Wars - http://www.windwardreports.com/film.htm
> 
> 
Date:Sat, 18 Aug 2007 03:08:04 -0700   Author:  

RE: How do I get the SMTP email address from web.config?   
worked great - thanks

-- 
thanks - dave
david_at_windward_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm




"Manish Bafna" wrote:


> Hi,
> First write below code in web.config  </system.web> and before 
> </configuration>:
> <system.net >
>     <mailSettings >
>     <smtp from="who@myhost.com">
>       <network host="mail.myhost.net" userName="xxxxx" password="xxxx"/>
>     </smtp>
>   </mailSettings>
>     </system.net >
> 
> Then try this code:
> Configuration configurationFile = 
> WebConfigurationManager.OpenWebConfiguration("~\\Web.config");
>         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;
> 
>             lblHost.Text = host;
>             lblUserName.Text = username;
>             lblPassword.Text = password;
>         }
> Also include following namespaces:
> using System.Configuration;
> using System.Web.Configuration;
> using System.Net.Configuration;
> -- 
> Hope this helps.
> Thanks and Regards.
> Manish Bafna.
> MCP and MCTS.
> 
> 
> 
> "David Thielen" wrote:
> 
> > I've tried:
> > MailSettingsSectionGroup mailConfig = 
> > WebConfigurationManager.GetSection("system.net/mailSettings") as 
> > MailSettingsSectionGroup;
> > 
> > and:
> > 	Configuration configurationFile = 
> > WebConfigurationManager.OpenWebConfiguration("/Web.Config");
> > 	MailSettingsSectionGroup mailConfig;
> > 	if (configurationFile != null)
> > 		mailConfig = configurationFile.GetSectionGroup("system.net/mailSettings") 
> > as MailSettingsSectionGroup;
> > 
> > The first method returns null and the second returns an object but it does 
> > not have the host or from properties set.
> > 
> > -- 
> > thanks - dave
> > david_at_windward_dot_net
> > http://www.windwardreports.com
> > 
> > Cubicle Wars - http://www.windwardreports.com/film.htm
> > 
> > 
Date:Sun, 19 Aug 2007 09:32:02 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us