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