473,659 Members | 2,526 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How do I get the SMTP email address from web.config?

I've tried:
MailSettingsSec tionGroup mailConfig =
WebConfiguratio nManager.GetSec tion("system.ne t/mailSettings") as
MailSettingsSec tionGroup;

and:
Configuration configurationFi le =
WebConfiguratio nManager.OpenWe bConfiguration( "/Web.Config");
MailSettingsSec tionGroup mailConfig;
if (configurationF ile != null)
mailConfig = configurationFi le.GetSectionGr oup("system.net/mailSettings")
as MailSettingsSec tionGroup;

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_windwa rd_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
Aug 18 '07 #1
2 14058
Hi,
First write below code in web.config </system.weband before
</configuration>:
<system.net >
<mailSettings >
<smtp from="wh*@myhos t.com">
<network host="mail.myho st.net" userName="xxxxx " password="xxxx"/>
</smtp>
</mailSettings>
</system.net >

Then try this code:
Configuration configurationFi le =
WebConfiguratio nManager.OpenWe bConfiguration( "~\\Web.config" );
MailSettingsSec tionGroup mailSettings =
configurationFi le.GetSectionGr oup("system.net/mailSettings") as
MailSettingsSec tionGroup;
if (mailSettings != null)
{
int port = mailSettings.Sm tp.Network.Port ;
string host = mailSettings.Sm tp.Network.Host ;
string password = mailSettings.Sm tp.Network.Pass word;
string username = mailSettings.Sm tp.Network.User Name;

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

"David Thielen" wrote:
I've tried:
MailSettingsSec tionGroup mailConfig =
WebConfiguratio nManager.GetSec tion("system.ne t/mailSettings") as
MailSettingsSec tionGroup;

and:
Configuration configurationFi le =
WebConfiguratio nManager.OpenWe bConfiguration( "/Web.Config");
MailSettingsSec tionGroup mailConfig;
if (configurationF ile != null)
mailConfig = configurationFi le.GetSectionGr oup("system.net/mailSettings")
as MailSettingsSec tionGroup;

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_windwa rd_dot_net
http://www.windwardreports.com

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

Aug 18 '07 #2
worked great - thanks

--
thanks - dave
david_at_windwa rd_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.weband before
</configuration>:
<system.net >
<mailSettings >
<smtp from="wh*@myhos t.com">
<network host="mail.myho st.net" userName="xxxxx " password="xxxx"/>
</smtp>
</mailSettings>
</system.net >

Then try this code:
Configuration configurationFi le =
WebConfiguratio nManager.OpenWe bConfiguration( "~\\Web.config" );
MailSettingsSec tionGroup mailSettings =
configurationFi le.GetSectionGr oup("system.net/mailSettings") as
MailSettingsSec tionGroup;
if (mailSettings != null)
{
int port = mailSettings.Sm tp.Network.Port ;
string host = mailSettings.Sm tp.Network.Host ;
string password = mailSettings.Sm tp.Network.Pass word;
string username = mailSettings.Sm tp.Network.User Name;

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

"David Thielen" wrote:
I've tried:
MailSettingsSec tionGroup mailConfig =
WebConfiguratio nManager.GetSec tion("system.ne t/mailSettings") as
MailSettingsSec tionGroup;

and:
Configuration configurationFi le =
WebConfiguratio nManager.OpenWe bConfiguration( "/Web.Config");
MailSettingsSec tionGroup mailConfig;
if (configurationF ile != null)
mailConfig = configurationFi le.GetSectionGr oup("system.net/mailSettings")
as MailSettingsSec tionGroup;

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_windwa rd_dot_net
http://www.windwardreports.com

Cubicle Wars - http://www.windwardreports.com/film.htm
Aug 19 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
1548
by: Srinivas | last post by:
Hi, I am using ASP.NET SmtpMail to send email using the following code public void SendEmail(string From, string To, string Subject, StringBuilder Message, string Attachment, string mailFormat) { MailMessage mailMessage = new MailMessage (); mailMessage.From = From; mailMessage.To = To;
34
18222
by: antonyliu2002 | last post by:
I've set up the virtual smtp server on my IIS 5.1 like so: 1. Assign IP address to "All Unassigned", and listen to port 25. 2. Access Connection granted to "127.0.0.1". 3. Relay only allow "127.0.0.1". 4. Authentication: "Anonymous access" only. 5. Outbound connection listen to TCP 25. Besides,
6
1523
by: Dushyant | last post by:
Hi everyone, I am working on an application, where I need to mail some xml files as attachments. I tried to use System.Diagnostic.Process class but it does not provide any help for attaching a file automatically. Then I resorted to System. Web namespace but here also it does not take the SMTP server's address automatically. I have to mention it. The application on which I am working is a general purpose application and user might not be...
6
2094
by: John Salerno | last post by:
If I want to write a cgi script that reads the contents of an HTML form and emails it to me, what would I use as the host parameter for my SMTP instance? The example in the docs is 'localhost', but I don't know what that means or refers to. I imagine I would have to use something that was tied to me specifically, but tied to what? My computer? My email address?
7
7730
by: oopsbabies | last post by:
Hello everyone, I am using Apache 1.3.33 as the web server and PHP version 4.3.10. My machine is using Windows XP 2002 professional edition which comes with a Windows firewall. I am using McAfee free edition for anti-virus. I use an ISP provider from my country and according to them I do not need to perform authentication while sending mails through their SMTP address. Thus I am using external SMTP server. I don't have IIS installed...
5
4215
by: Sin Jeong-hun | last post by:
Hi. I would like to let users send bug reports or other messages to me. Maybe the easiest way to send e-mails from my application is just use the default e-mail agent by executing a link mailto://mymail@domail.com. But this only works if the user has configured Outlook or something. Many users use web-based mails here so if I do so, Outlook Express's a new account wizard will pop-up. Futhure more this reveals user e-mails. Some people...
16
2988
by: bgreer5050 | last post by:
I have a form with the following fields: UserEmail Subject Body When the form is submitted, the email is processed fine. When I try to add another field to the mm.body (mm.Body = Body.Text & Listbox1.SelectedItem.Text) the smtp.Send fails. Any ideas ?
2
1857
by: Bgreer5050 | last post by:
I posted a problem with sending email via smtp using Dot Net 2.0 I was told to look at adding authentication to my web.config file; I added the following: authenticationMode="SSL" I put this in my web.config mail settings and when I put the mouse over it, i get the following message:
6
5190
by: phpmagesh | last post by:
Hi, I am using mail function in my php page, As soon i update the details, i have to send mail to the customer with the updated details, problem is when i send mail it simple through waring msg as: can anyone help me why such problem occurs, how to over come this problem.
0
8428
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8341
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8751
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8539
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7360
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
2
1982
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.