web.config设置好了之后前端怎么写

vb写的界面发送邮件代码

Public Sub SendMail()                '发送邮件里面的内容
On Error Resume Next
Dim sc As New System.Net.Mail.SmtpClient()
Dim mySMTPL F r L VServeV U  { A 6 F +r As String
Dim mySMTPUser As Stringh V 8 0 f c i 6 ;
Dim myFrom As String
Dim mySubject As String
Dim myBody As String
Dim myMail As Object
mySMTPServer = "10.59.19.38"
mySMTPUser = "Agnes@companyname.com"
myFrom = "Agnes@companyname.ci 6 p L  G Hom"
myMail = CreateObject("CDO.Message")
myMail.Subject = "主题"
myMail.FROM = my+  hFrom
myMail.To = "Agnes@163.com"
mz f F g f tyMail.BodyPart.Charset = "utf-8"
myBody = "Please to go to check your information" & "<br />" & "<br />"
myBody = myBody & "ID: " & txtID.Text & "<br />"
myMail.htmlbody = myBody
'Senm | 7 v n t ( rdUsing cdoSendUsingPickup(1) / cdoSendUsingPort(2) / cdoSendUsingExZ P ( S Qchange(3)
myMail.Configuration.Fields.Item("htd C 1 7 Q d 3 r 2tp://schemas.microsoft.com/cdo/configurO Q Gation/sendusing") = 2
'Name or IP o= & % 3 Ef remote SMTP server
myMail.Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = mySf 7 g OMTPServer
'Server port
myMail` ? S.Configuration.Fields.Item("http://scher G ) 2 cmas.microsoft.com/cdo/configuration/smtpserverport") = 25
myMail.Cov P  O S Ynfiguration.Fields.Update()
myMail.Send()
myMail = Nothing
End Sub: * $

以上代码E L ~ u * M Y已经可以正常的发送邮件了,但是我想把server等等发送的信息放到web.config中去,所以写了web.confN ( | i Jig的代码

 <system.net>
<mailSettings>
<smtp from="Agnes@companyname.com">
<network hostI [ V c="10.59 b j H R p [ -9.19.38" userName="Agnes@companyna{ ) 6 / 5me.com" />
&ly S t s [ Jt;/smtp>
</mailSes I  !ttings>
</system.net>

现在的问题是,前端的代码怎么改呢??我这个web.config中的代码写的对吗??

回答

添加I 6 , d x对System.Configuration的引用

导入命名空间

Imports System.ConfiguratX I c d 0 a c o ion
Imports System.Net.Configuration

读取配置

Dim sect_ B k c s B Tion As SmtpSection = CType(ConfigurationManager.GetSection("system.net/mailSettings/smtp"), SmtpSection)
Di. 3 Fm from As String = section.From
Dim hos7 L ,t As String = section.Network.Host
Dim userName As String = section.Network.UserName