将ASP.Net System.Net.Mail设置移动到Web.config
发布时间:2020-12-16 07:34:20 所属栏目:asp.Net 来源:网络整理
导读:我们使用此编码从ASP.Net代码隐藏的Vb.Net文件发送电子邮件. 可以将任何此编码放在Web.config文件中吗? Protected Sub EmailStudentList() ' Get the rendered HTML. '----------------------- Dim SB As New StringBuilder() Dim SW As New StringWriter(S
我们使用此编码从ASP.Net代码隐藏的Vb.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 解决方法<system.net> <mailSettings> <smtp from="ourEmail@gmail.com"> <network defaultCredentials="false" userName="ourEmailUsername@gmail.com" password="ourPassword" host="smtp.gmail.com" enableSsl="true" port="587"/> </smtp> </mailSettings> </system.net> (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- asp.net-mvc – MVC将null反序列化为“null”(字符串)
- 在(asp.net wcf)Web应用程序中存储文件的最佳方法是什么
- ASP.NET Cookieless Forms在登录页面被加入书签时不设置coo
- 请求的ASP.NET窗体身份验证失败 原因:提供的票已过期
- asp.net – 在Response.RedirectToRoute之后跳过页面执行的
- 单元测试ASP.NET MVC重定向
- Razor 页面简化了 ASP.NET MVC 应用程序
- asp.net-core – 从ActionFilterAttribute设置ViewBag
- 有哪些方法可以优化ASP.NET缓存的使用?
- asp.net – 安装MS Web Deploy 3.0 – 无法启动WMService
推荐文章
站长推荐
- asp.net-mvc – ASP.NET MVC的生产力?
- asp.net-mvc-4 – 使用从控制器操作返回的JSON.N
- 我们可以通过.net native编译asp.net 5应用程序吗
- asp.net-core – ASP.NET核心DisplayAttribute本
- 在asp.net mvc中实现“关注人,发布”功能
- asp.net-mvc – 在ASP.NET MVC 3中使用Ajax响应发
- 模型更改检测ASP.NET代码首次迁移
- asp.net – 如何在Firefox中解码来自jQuery $.aj
- asp.net-web-api – 如何在Swashbuckle中替换Swa
- asp.net-mvc – Breeze.js失败,无法加载文件或程
热点阅读