Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/30.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将ASP.Net System.Net.Mail设置移动到Web.config_Asp.net_Vb.net_Email_Web Config_Settings - Fatal编程技术网

将ASP.Net System.Net.Mail设置移动到Web.config

将ASP.Net System.Net.Mail设置移动到Web.config,asp.net,vb.net,email,web-config,settings,Asp.net,Vb.net,Email,Web Config,Settings,我们使用此代码从Vb.Net文件后面的ASP.Net代码发送电子邮件 这些编码是否可以放在Web.config文件中 Protected Sub EmailStudentList() ' Get the rendered HTML. '----------------------- Dim SB As New StringBuilder() Dim SW As New StringWriter(SB) Dim htmlTW As New HtmlText

我们使用此代码从Vb.Net文件后面的ASP.Net代码发送电子邮件

这些编码是否可以放在Web.config文件中

Protected Sub EmailStudentList()

    ' Get the rendered HTML.
    '-----------------------
    Dim SB As New StringBuilder()
    Dim SW As New StringWriter(SB)
    Dim htmlTW As New HtmlTextWriter(SW)

    GridViewSummary.RenderControl(htmlTW)

    ' Get the HTML into a string.
    ' This will be used in the body of the email report.
    '---------------------------------------------------
    Dim dataGridHTML As String = SB.ToString()

    Dim SmtpServer As New SmtpClient()
    SmtpServer.Credentials = New Net.NetworkCredential("ourEmailUsername@gmail.com", "ourPassword")
    SmtpServer.Port = 587
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True

    ObjMailMessage = New MailMessage()

    Try
        ObjMailMessage.From = New MailAddress("ourEmail@gmail.com", "Some text is here.", System.Text.Encoding.UTF8)
        ObjMailMessage.To.Add(New MailAddress("BoardOfDirectors@gmail.com", "Emad-ud-deen", System.Text.Encoding.UTF8))
        ObjMailMessage.Subject = "List of enrolled students for the board of directors"
        ObjMailMessage.Body = dataGridHTML
        ObjMailMessage.IsBodyHtml = True
        ObjMailMessage.DeliveryNotificationOptions = DeliveryNotificationOptions.OnFailure

        SmtpServer.Send(ObjMailMessage)

    Catch ex As Exception
        MsgBox(ex.ToString())
    End Try
End Sub

您不能在配置文件中放置“code”,但可以移动许多设置


我已经将其中一些项目放在了web.config`

<system.net>
    <mailSettings>
        <smtp>
            <network host="<<Host IP Address>>" port="<<Host Port Number>>" userName="" password=""/>
        </smtp>
    </mailSettings>
    <defaultProxy useDefaultCredentials="false">
        <proxy bypassonlocal="true" usesystemdefault="false"/>
    </defaultProxy>
</system.net>

以下链接也可能有所帮助:


非常感谢您这么快的回复!非常有用。:-)很乐意帮忙。看起来我们都得到了同样的答案,这让人放心。
<configuration>
  <system.net>
    <mailSettings>
      <smtp deliveryMethod="network">
        <network
          host="localhost"
          port="25"
          defaultCredentials="true"
        />
      </smtp>
    </mailSettings>
  </system.net>
</configuration>
<system.net>
    <mailSettings>
        <smtp>
            <network host="<<Host IP Address>>" port="<<Host Port Number>>" userName="" password=""/>
        </smtp>
    </mailSettings>
    <defaultProxy useDefaultCredentials="false">
        <proxy bypassonlocal="true" usesystemdefault="false"/>
    </defaultProxy>
</system.net>