【发布时间】:2021-03-24 16:42:57
【问题描述】:
我正在为一个网站编写一个简单的联系表单,并且需要使用 ASP.NET 中的 WebMail 将表单的内容发布到转发电子邮件中。我使用了 Microsoft 文档在此处提供的指南-> Sending Email from an ASP.NET Web Pages (Razor) Site。
该表单发布到一个名为 ProcessRequest.cshtml 的新页面,就像文档显示的那样,该页面应该使用 SMTP 将带有 WebMail 的消息发送到我提供的转发电子邮件地址,然后转发给我。
当我运行我的代码时,我最终在 ProcessRequest.cshtml 页面上收到错误消息:操作已超时。 以及将要发送的电子邮件(所以我知道表单是被发回服务器并可以访问,只是没有从我的表单中获取到转发帐户。
我认为问题要么是 WebMail 助手的设置、我的 GoDaddy 帐户,要么是我试图在 localhost 上测试它而不是实时的事实。当然,Godaddy 没有任何帮助。这是表格:
<div class="card white-background-area ">
<form method="POST" action="ProcessRequest.cshtml">
<fieldset>
<div class="form-group">
<label for="name">Name: *</label>
<input type="text" class="form-control" id="name" placeholder="Enter Your Name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email address: *</label>
<input type="email" class="form-control" id="email" placeholder="Enter email" name="email" required>
</div>
<div class="form-group">
<label for="question">Enter your question here: *</label>
<textarea class="form-control" name="question" id="question"></textarea>
</div>
<div class="mb-5">
<button type="submit" class="btn btn-primary">Submit</button>
<button type="reset" class="btn btn-primary">Reset</button>
</div>
<p>* = required</p>
</fieldset>
</form>
</div>
</div>
这是 ProcessRequest.cshtml 页面:
ViewBag.Title = "ProcessRequest.cshtml";
var name = Request["name"];
var email = Request["email"];
var message = Request["question"];
var errorMessage = "";
var debuggingFlag = true;
try
{
// Initialize WebMail helper
WebMail.SmtpServer = "smtpout.secureserver.net";
WebMail.SmtpPort = 465;
WebMail.From = "forwardingemail@url.com";
// Send email
WebMail.Send(to: email,
subject: "Help request from - " + name,
body: message
);
}
catch (Exception ex)
{
errorMessage = ex.Message;
}
}
<!DOCTYPE html>
<html>
<head>
<title>Request for Assistance</title>
</head>
<body>
<p>Sorry to hear that you are having trouble, <b>@name</b>.</p>
@if (errorMessage == "")
{
<p>
An email message has been sent to our customer service
department regarding the following problem:
</p>
<p><b>@message</b></p>
}
else
{
<p><b>The email was <em>NOT</em> sent.</b></p>
<p>This email would contain:</p>
<p>@name</p>
<p>@email</p>
<p>@message</p>
<p>
Please check that the code in the ProcessRequest page has
correct settings for the SMTP server name, a user name,
a password, and a "from" address.
</p>
if (debuggingFlag)
{
<p>The following error was reported:</p>
<p><em>@errorMessage</em></p>
}
}
</body>
</html>
在此先感谢您帮助我。
【问题讨论】:
-
验证服务器地址和端口号是否正确。大多数 SMTP 流量在端口 25 上运行,不再广泛支持使用 465。您需要与 SMTP 服务提供商确认他们支持哪些端口。
-
我终于联系上了 godaddy 的某个人,他说我不能在联系表单中使用转发地址,因为这是一种欺骗形式,而且我实际上没有该帐户的密码和用户名用于网络邮件。所以看起来它必须是一封普通的电子邮件。无法通过 godaddy 转发电子邮件。