GoDaddy 在 ASP.NET C# 中使用 SMTP 和 WebMail 转发电子邮件

问题描述

我正在为网站编写一个简单的联系表单,需要使用 ASP.NET 中的 WebMail 将表单内容发布到转发电子邮件。我使用了 Microsoft 文档提供的指南 -> Sending Email from an ASP.NET Web Pages (Razor) Site

表单发布到一个名为 ProcessRequest.cshtml 的新页面,就像文档显示的那样,它应该使用 SMTP 将带有 WebMail 的消息发送到我提供的转发电子邮件地址,然后转发给我。

当我运行我的代码时,我最终收到错误消息:操作超时。 在 ProcessRequest.cshtml 页面上以及将发送的电子邮件(所以我知道表单是被回发到服务器并可以访问,只是无法从我的表单发送到转发帐户。

我认为问题要么是 WebMail 助手的设置、我的 GoDaddy 帐户,要么是我试图在本地主机上测试它而不是实时测试。当然,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 = "[email protected]";

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

预先感谢您帮助我解决这个问题。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)