ASP.NET Web Pages Email

asp.net web pages - webmail 帮助器

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

webmail 帮助器

webmail 帮助器让发送邮件变得更简单,它按照 smtp(simple mail transfer protocol 简单邮件传输协议)从 web 应用程序发送邮件。

前提:电子邮件支持

为了演示如何使用电子邮件,我们将创建一个输入页面,让用户提交一个页面到另一个页面,并发送一封关于支持问题的邮件。

第一:编辑您的 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 事务(电子邮件)的端口。

enablessl: 如果服务器使用 ssl(secure socket layer 安全套接层)加密,则值为 true。

username: 用于发送电子邮件的 smtp 电子邮件账户的名称。

password: smtp 电子邮件账户的密码。

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>
}
}

想了解更多关于 asp.net web pages 应用程序发送电子邮件的信息,请查阅:webmail 对象参考手册


相关文章