当前位置: 移动技术网 > IT编程>开发语言>.net > ASP.NET Web Pages - WebMail 帮助器

ASP.NET Web Pages - WebMail 帮助器

2018年09月29日  | 移动技术网IT编程  | 我要评论

同煤集团吧,陈慧琳老公是谁,齐一心

webmail 帮助器 - 众多有用的 asp.net web 帮助器之一。

webmail 帮助器

webmail 帮助器使我们更容易从 web 应用程序中使用 smtp 来发送电邮。



脚本: email 支持

为了演示电子邮件的使用,我们将创建用于技术支持的输入页面,让用户向另一个页面提交该页面,然后发送一封有关支持问题的电子邮件。



首先:编辑您的 appstart 页面

如果您曾构建过本教程中的 demo 应用程序,那么站点中应该存在拥有如下内容的 _appstart.cshtml 页面:

_appstart.cshtml

@{
websecurity.initializedatabaseconnection("users", "userprofile", "userid", "email", 
true);
}

如需初始化 webmail 帮助器,请向您的 appstart 页面添加以下 webmail 属性:

_appstart.cshtml

@{
websecurity.initializedatabaseconnection("users", "userprofile", "userid", "email", 
true);
webmail.smtpserver = "smtp.example.com";
webmail.smtpport = 25;
webmail.enablessl = false;
webmail.username = "support@example.com";
webmail.password = "password-goes-here";
webmail.from = "john@example.com";
}

属性解释:

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:"someone@example.com", 
subject: "help request from - " + customeremail, 
body: customerrequest ); 
}
catch (exception ex )
{
<text>@ex</text> 
}
}

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网