ASP.NET Web Pages - WebMail 帮助器
如果您曾构建过本教程中的 DEMO 应用程序,那么站点中应该存在拥有如下内容的 _AppStart.cshtml 页面: _AppStart.cshtml@{ WebSecurity.InitializeDatabaseConnection("Users","UserProfile","UserId","Email",true); } 如需初始化 WebMail 帮助器,请向您的 AppStart 页面添加以下 WebMail 属性: _AppStart.cshtml@{ WebSecurity.InitializeDatabaseConnection("Users",true); WebMail.SmtpServer = "smtp.example.com"; WebMail.SmtpPort = 25; WebMail.EnableSsl = false; WebMail.UserName = "[email?protected]"; WebMail.Password = "password-goes-here"; WebMail.From = "[email?protected]"; } 属性解释:SmtpServer: 发送电邮所使用的 SMTP 服务器的名称。 SmtpPort: 发送 SMTP transactions (电邮) 所用的服务器端口。 EnableSsl: True,如果服务器应该使用 SSL (Secure Socket Layer) 加密。 UserName: 发送电邮所用的 SMTP email 账户的名称。 Password: SMTP 电邮账户的密码。 From: 出现在 from 栏中的电邮地址(通常与 UserName 相同)。 第二:创建电邮输入页面然后创建输入页面,名为 Email_Input: Email_Input.cshtml<!DOCTYPE html> <html> <body> <h1>Request for Assistance</h1> <form method="post" action="EmailSend.cshtml"> <label>Username:</label> <input type="text name="customerEmail" /> <label>Details about the problem:</label> <textarea name="customerRequest" cols="45" rows="4"></textarea> <p><input type="submit" value="Submit" /></p> </form> </body> </html> 输入页面的作用是收集信息,然后把数据提交到一个能够将信息作为邮件来发送的新页面。 第三:创建邮件发送页面然后创建用于发送电邮的页面,名为 Email_Send: Email_Send.cshtml@{ // Read input var customerEmail = Request["customerEmail"]; var customerRequest = Request["customerRequest"]; try { // Send email WebMail.Send(to:"[email?protected]",subject: "Help request from - " + customerEmail,body: customerRequest ); } catch (Exception ex ) { <text>@ex</text> } } 如需更多有关从 ASP.NET Web Pages 应用程序发送电子邮件的信息 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
- dependency-injection – asp.net 5依赖注入拦截调用方法
- asp.net – 所有PartialView的自定义ActionResult等效模型
- 常用正则表达式
- asp.net-mvc-3 – MVC3重定向到ajax调用后的动作
- entity-framework-4 – 在我的自定义MembershipProvider中使
- asp.net-mvc – ASP.NET MVC,MVCContrib,Structuremap,让它
- 处理用户在ASP.NET MVC网站中点击“Enter”键
- asp.net – 无法加载文件或程序集“System.Web.Mvc,Version
- asp.net-mvc – 在Tag Helper上拥有ViewContext属性的目的是
- asp.net-mvc – 我的MVC 5模板中没有ApplicationRoleManage
- asp.net-mvc – 为什么需要为Html.Action定义的路
- asp.net-core – Controller.json设置Serializat
- 是否可以运行异步调用来在ASP.NET中设置会话?
- asp.net-mvc – 使用MVC Futures的异步控制器在.
- asp.net-mvc-2 – 后退按钮不请求asp.net mvc ge
- 如何以编程方式将ListItems添加到ASP.NET中的Dro
- .net – 实现UserManager以使用自定义类和存储过
- asp.net-mvc-3 – 无法在MVC3 HTML Helper中获取
- 经典ASP和UTF-8
- asp.net-mvc – MVC Razor ViewEngine不是线程安