473,394 Members | 1,641 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

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.Configuration.MailSettingsSectionGroup
Dim smtpClient As New System.Net.Mail.SmtpClient
smtpClient.Host = mailSettings.Smtp.Network.Host
smtpClient.UseDefaultCredentials = False
smtpClient.Port = mailSettings.Smtp.Network.Port
smtpClient.DeliveryMethod =
System.Net.Mail.SmtpDeliveryMethod.Network
smtpClient.Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)

smtpClient.Send(message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod = "network">
<network defaultCredentials = "true"
host = "mail.domain.com"
password = "secret"
port = "25"

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

I am getting the error:
"ConfigurationSectionGroup 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 7531
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.Configuration.MailSettingsSectionGroup
Dim smtpClient As New System.Net.Mail.SmtpClient
smtpClient.Host = mailSettings.Smtp.Network.Host
smtpClient.UseDefaultCredentials = False
smtpClient.Port = mailSettings.Smtp.Network.Port
smtpClient.DeliveryMethod =
System.Net.Mail.SmtpDeliveryMethod.Network
smtpClient.Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)

smtpClient.Send(message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod = "network">
<network defaultCredentials = "true"
host = "mail.domain.com"
password = "secret"
port = "25"

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

I am getting the error:
"ConfigurationSectionGroup 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*********************@b28g2000cwb.googlegro ups.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.Configuration.MailSettingsSectionGroup
Dim smtpClient As New System.Net.Mail.SmtpClient
smtpClient.Host = mailSettings.Smtp.Network.Host
smtpClient.UseDefaultCredentials = False
smtpClient.Port = mailSettings.Smtp.Network.Port
smtpClient.DeliveryMethod =
System.Net.Mail.SmtpDeliveryMethod.Network
smtpClient.Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)

smtpClient.Send(message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod = "network">
<network defaultCredentials = "true"
host = "mail.domain.com"
password = "secret"
port = "25"

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

I am getting the error:
"ConfigurationSectionGroup 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 configurationFile As Configuration =
System.Web.Configuration.WebConfigurationManager.O penWebConfiguration("~/Web.Config")

' Create mail settings section group
Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
configurationFile.GetSectionGroup("system.net/mailSettings")

' Define smtp client properties
If Not mailSettings Is Nothing Then
With smtpClient
.Port = mailSettings.Smtp.Network.Port
.Host = mailSettings.Smtp.Network.Host
.Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)
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*********************@b28g2000cwb.googlegro ups.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.Configuration.MailSettingsSectionGroup
Dim smtpClient As New System.Net.Mail.SmtpClient
smtpClient.Host = mailSettings.Smtp.Network.Host
smtpClient.UseDefaultCredentials = False
smtpClient.Port = mailSettings.Smtp.Network.Port
smtpClient.DeliveryMethod =
System.Net.Mail.SmtpDeliveryMethod.Network
smtpClient.Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)

smtpClient.Send(message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod = "network">
<network defaultCredentials = "true"
host = "mail.domain.com"
password = "secret"
port = "25"

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

I am getting the error:
"ConfigurationSectionGroup 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.googlegro ups.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 configurationFile As Configuration =
System.Web.Configuration.WebConfigurationManager.O penWebConfiguration("~/Web.Config")

' Create mail settings section group
Dim mailSettings As
System.Net.Configuration.MailSettingsSectionGroup =
configurationFile.GetSectionGroup("system.net/mailSettings")

' Define smtp client properties
If Not mailSettings Is Nothing Then
With smtpClient
.Port = mailSettings.Smtp.Network.Port
.Host = mailSettings.Smtp.Network.Host
.Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)
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*********************@b28g2000cwb.googlegro ups.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.Configuration.MailSettingsSectionGroup
Dim smtpClient As New System.Net.Mail.SmtpClient
smtpClient.Host = mailSettings.Smtp.Network.Host
smtpClient.UseDefaultCredentials = False
smtpClient.Port = mailSettings.Smtp.Network.Port
smtpClient.DeliveryMethod =
System.Net.Mail.SmtpDeliveryMethod.Network
smtpClient.Credentials = New
System.Net.NetworkCredential(mailSettings.Smtp.Net work.UserName,
mailSettings.Smtp.Network.Password)

smtpClient.Send(message)
...

And in my Web.Config file I have:

<system.net>
<mailSettings>
<smtp deliveryMethod = "network">
<network defaultCredentials = "true"
host = "mail.domain.com"
password = "secret"
port = "25"

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

I am getting the error:
"ConfigurationSectionGroup 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
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...
13
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...
16
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...
3
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."...
3
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...
1
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...
5
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...
3
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....
11
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...
5
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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...
0
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...
0
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...

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.