473,725 Members | 1,980 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Asp.Net 2.0 Net.Mail. I don't know what else to try. Thanks.

Hello,

I am trying to send an email from a form in my web page.

I have the following codes:

...
Dim mailSettings As New
System.Net.Conf iguration.MailS ettingsSectionG roup
Dim smtpClient As New System.Net.Mail .SmtpClient
smtpClient.Host = mailSettings.Sm tp.Network.Host
smtpClient.UseD efaultCredentia ls = False
smtpClient.Port = mailSettings.Sm tp.Network.Port
smtpClient.Deli veryMethod =
System.Net.Mail .SmtpDeliveryMe thod.Network
smtpClient.Cred entials = New
System.Net.Netw orkCredential(m ailSettings.Smt p.Network.UserN ame,
mailSettings.Sm tp.Network.Pass word)

smtpClient.Send (message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings >
<smtp deliveryMethod = "network">
<network defaultCredenti als = "true"
host = "mail.domain.co m"
password = "secret"
port = "25"

userName = "us**@domain.co m" />
</smtp>
</mailSettings>
</system.net>

I am getting the error:
"ConfigurationS ectionGroup cannot be edited before being added to a
section group belonging to an instance of class Configuration"

I looked for a solution all day and I can't solve this.

Could someone tell me what am I doing wrong here?

Thanks,
Miguel

Nov 15 '06 #1
4 7556
I think what's happening here is you are using the "new" keyword, e.g. you
are trying to create a new section instead of reading the existing one.
Here's a link to the documentation on how you "read" the settings:

http://msdn2.microsoft.com/en-gb/lib...roup.smtp.aspx

Peter
--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"shapper" wrote:
Hello,

I am trying to send an email from a form in my web page.

I have the following codes:

...
Dim mailSettings As New
System.Net.Conf iguration.MailS ettingsSectionG roup
Dim smtpClient As New System.Net.Mail .SmtpClient
smtpClient.Host = mailSettings.Sm tp.Network.Host
smtpClient.UseD efaultCredentia ls = False
smtpClient.Port = mailSettings.Sm tp.Network.Port
smtpClient.Deli veryMethod =
System.Net.Mail .SmtpDeliveryMe thod.Network
smtpClient.Cred entials = New
System.Net.Netw orkCredential(m ailSettings.Smt p.Network.UserN ame,
mailSettings.Sm tp.Network.Pass word)

smtpClient.Send (message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings >
<smtp deliveryMethod = "network">
<network defaultCredenti als = "true"
host = "mail.domain.co m"
password = "secret"
port = "25"

userName = "us**@domain.co m" />
</smtp>
</mailSettings>
</system.net>

I am getting the error:
"ConfigurationS ectionGroup cannot be edited before being added to a
section group belonging to an instance of class Configuration"

I looked for a solution all day and I can't solve this.

Could someone tell me what am I doing wrong here?

Thanks,
Miguel

Nov 15 '06 #2
Please review this forum post by Ryan Olsham, MVP :

http://forums.asp.net/thread/1437034.aspx

It shows you the correct way to access mailsettings in web.config.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"shapper" <md*****@gmail. comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
Hello,

I am trying to send an email from a form in my web page.

I have the following codes:

...
Dim mailSettings As New
System.Net.Conf iguration.MailS ettingsSectionG roup
Dim smtpClient As New System.Net.Mail .SmtpClient
smtpClient.Host = mailSettings.Sm tp.Network.Host
smtpClient.UseD efaultCredentia ls = False
smtpClient.Port = mailSettings.Sm tp.Network.Port
smtpClient.Deli veryMethod =
System.Net.Mail .SmtpDeliveryMe thod.Network
smtpClient.Cred entials = New
System.Net.Netw orkCredential(m ailSettings.Smt p.Network.UserN ame,
mailSettings.Sm tp.Network.Pass word)

smtpClient.Send (message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings >
<smtp deliveryMethod = "network">
<network defaultCredenti als = "true"
host = "mail.domain.co m"
password = "secret"
port = "25"

userName = "us**@domain.co m" />
</smtp>
</mailSettings>
</system.net>

I am getting the error:
"ConfigurationS ectionGroup cannot be edited before being added to a
section group belonging to an instance of class Configuration"

I looked for a solution all day and I can't solve this.

Could someone tell me what am I doing wrong here?

Thanks,
Miguel

Nov 15 '06 #3
Hi,

I solved it this way:

' Create and define the SMTP client
Dim smtpClient As New System.Net.Mail .SmtpClient

' Create access to configuration file
Dim configurationFi le As Configuration =
System.Web.Conf iguration.WebCo nfigurationMana ger.OpenWebConf iguration("~/Web.Config")

' Create mail settings section group
Dim mailSettings As
System.Net.Conf iguration.MailS ettingsSectionG roup =
configurationFi le.GetSectionGr oup("system.net/mailSettings")

' Define smtp client properties
If Not mailSettings Is Nothing Then
With smtpClient
.Port = mailSettings.Sm tp.Network.Port
.Host = mailSettings.Sm tp.Network.Host
.Credentials = New
System.Net.Netw orkCredential(m ailSettings.Smt p.Network.UserN ame,
mailSettings.Sm tp.Network.Pass word)
End With
End If

Thanks,
Miguel

Juan T. Llibre wrote:
Please review this forum post by Ryan Olsham, MVP :

http://forums.asp.net/thread/1437034.aspx

It shows you the correct way to access mailsettings in web.config.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"shapper" <md*****@gmail. comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
Hello,

I am trying to send an email from a form in my web page.

I have the following codes:

...
Dim mailSettings As New
System.Net.Conf iguration.MailS ettingsSectionG roup
Dim smtpClient As New System.Net.Mail .SmtpClient
smtpClient.Host = mailSettings.Sm tp.Network.Host
smtpClient.UseD efaultCredentia ls = False
smtpClient.Port = mailSettings.Sm tp.Network.Port
smtpClient.Deli veryMethod =
System.Net.Mail .SmtpDeliveryMe thod.Network
smtpClient.Cred entials = New
System.Net.Netw orkCredential(m ailSettings.Smt p.Network.UserN ame,
mailSettings.Sm tp.Network.Pass word)

smtpClient.Send (message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings >
<smtp deliveryMethod = "network">
<network defaultCredenti als = "true"
host = "mail.domain.co m"
password = "secret"
port = "25"

userName = "us**@domain.co m" />
</smtp>
</mailSettings>
</system.net>

I am getting the error:
"ConfigurationS ectionGroup cannot be edited before being added to a
section group belonging to an instance of class Configuration"

I looked for a solution all day and I can't solve this.

Could someone tell me what am I doing wrong here?

Thanks,
Miguel
Nov 15 '06 #4
re:
Thanks
You're quite welcome, Miguel.
Glad to see you're up and running.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"shapper" <md*****@gmail. comwrote in message
news:11******** **************@ m7g2000cwm.goog legroups.com...
Hi,

I solved it this way:

' Create and define the SMTP client
Dim smtpClient As New System.Net.Mail .SmtpClient

' Create access to configuration file
Dim configurationFi le As Configuration =
System.Web.Conf iguration.WebCo nfigurationMana ger.OpenWebConf iguration("~/Web.Config")

' Create mail settings section group
Dim mailSettings As
System.Net.Conf iguration.MailS ettingsSectionG roup =
configurationFi le.GetSectionGr oup("system.net/mailSettings")

' Define smtp client properties
If Not mailSettings Is Nothing Then
With smtpClient
.Port = mailSettings.Sm tp.Network.Port
.Host = mailSettings.Sm tp.Network.Host
.Credentials = New
System.Net.Netw orkCredential(m ailSettings.Smt p.Network.UserN ame,
mailSettings.Sm tp.Network.Pass word)
End With
End If

Thanks,
Miguel

Juan T. Llibre wrote:
Please review this forum post by Ryan Olsham, MVP :

http://forums.asp.net/thread/1437034.aspx

It shows you the correct way to access mailsettings in web.config.

Juan T. Llibre, asp.net MVP
asp.net faq : http://asp.net.do/faq/
foros de asp.net, en español : http://asp.net.do/foros/
=============== =============== =====
"shapper" <md*****@gmail. comwrote in message
news:11******** *************@b 28g2000cwb.goog legroups.com...
Hello,

I am trying to send an email from a form in my web page.

I have the following codes:

...
Dim mailSettings As New
System.Net.Conf iguration.MailS ettingsSectionG roup
Dim smtpClient As New System.Net.Mail .SmtpClient
smtpClient.Host = mailSettings.Sm tp.Network.Host
smtpClient.UseD efaultCredentia ls = False
smtpClient.Port = mailSettings.Sm tp.Network.Port
smtpClient.Deli veryMethod =
System.Net.Mail .SmtpDeliveryMe thod.Network
smtpClient.Cred entials = New
System.Net.Netw orkCredential(m ailSettings.Smt p.Network.UserN ame,
mailSettings.Sm tp.Network.Pass word)

smtpClient.Send (message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings >
<smtp deliveryMethod = "network">
<network defaultCredenti als = "true"
host = "mail.domain.co m"
password = "secret"
port = "25"

userName = "us**@domain.co m" />
</smtp>
</mailSettings>
</system.net>

I am getting the error:
"ConfigurationS ectionGroup cannot be edited before being added to a
section group belonging to an instance of class Configuration"

I looked for a solution all day and I can't solve this.

Could someone tell me what am I doing wrong here?

Thanks,
Miguel

Nov 15 '06 #5

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

Similar topics

6
4225
by: pee2pee | last post by:
Hi, I have below code: <html> <head> <title>Contacting Worldpay, Please wait.......</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body text="#CCCCCC">
13
4488
by: Peter Amberg | last post by:
I would like to create a link on my page that opens the standard e-mail application when someone clicks it. It should have at least the subject preset, better if I could preset the body as well. I read somewhere that the TITLE attribute of the A HREF tag can be used to set a subject, so I tried: <A HREF="mailto:" TITLE="MySubject"> This would open the e-mail application, but the TITLE attribute is completely ignored, at least on...
16
2375
by: polilop | last post by:
I made a form in which I send the visitor a link to my page but when the visitor gets that link in the mail it dosent send him to the page just says invalid syntax or something like outbound....... I'm not trying to spam this is the code iput into body variable text= "<table width='310' border='0'> "&_ "<tr><td class='all'><p align='center'> Something <br>"&_ "something<br>"&_
3
2100
by: Eric | last post by:
When I use system.web.mail namespace in most of my integration programs and in windows application programs it doesn't work. it normally gives an exception "Could not access 'CDO.Message' object." or "Could not access MAPI drivers". (all these machines, outlook is not installed and local SMTP is installed and delivery configured to relay to the mail server. all my win32 services runs under administrator.) I was under the impression that...
3
3036
by: RN | last post by:
I am tired of sending mail from the built-in SMTP service for so many reasons (errors are nondescriptive in the event log, it doesn't let me control which IP address it sends from, and it identifies itself as the computer name which is not in domain.com format, triggering spam filter problems). Instead, I want to have my code send through an SMTP server of a company that we pay for mail service. But they require a username and password....
1
1480
by: Bob | last post by:
Vs2005 - Framework2. Just to let all of you know. I have found that I can not use an application to send e-mails using the system,net.mail namespace while Outlook express is opened on the same machine from which my program is trying to send an e-mail using smtp mail set to the same smtp server account as the currently selected outlook mail account. (code snippet follows at end) the application just does not send e-mail and no exception is...
5
2366
by: Robert Dufour | last post by:
I am trying to use framework 1.1 - stuck with it. to send emails from a windows form application. The email messages can have attachments, usually two and they can be either text or sounds (wav files) or images (bmp, gif or tiff) I can send the email messages OK but the attachments are giving me grief. Can anyone provide some code that adds attachments to web mail messages. Thanks for any help,
3
1896
by: Dudely | last post by:
I'm trying to debug someone else's third party code that I'm trying to install on my site. It works for him on his site, but not for me on "my" site. I've traced the problem to the mail() call. For whatever reason, it's failing. And, my question is - how do I make php print the real reason for the failure? I've modified his code (multiple times), so that it now looks like this:
11
3508
by: Ed Bitzer | last post by:
I have been able using the namespace System.Web.Mail and its method Smtp.mail.send to mail simple text messages to a small group within our 55 and older community. I need help expanding the programs capabilities. Searching this forum I did not find any related information so if I have chosen poorly, I would appreciate a suggestion of a more appropriate dotnet forum. Now what I wish is the ability to send bcc's rather than to: (would be...
5
2407
by: Henry Stock | last post by:
My ISP provides this sample for an ASP.NET capable email form. If you have any idea about how to do the following, I would greatly appreciate your help. I have a few alterations that I would like to implement, but I am not sure where to begin. First:
0
8752
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
9401
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
9257
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...
0
9111
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...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2157
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.