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