【问题标题】:Setting up Outgoing Email settings in Webmatrix在 Webmatrix 中设置外发电子邮件设置
【发布时间】:2014-11-24 19:49:07
【问题描述】:

我一直在尝试使用以下方法设置电子邮件身份验证:

OAuthWebSecurity.RegisterGoogleClient();

WebMail.SmtpServer = "stmp.gmail.com";
WebMail.SmtpPort = 465;
WebMail.EnableSsl = true;
WebMail.UserName = "username@gmail.com";
WebMail.Password = "mypassword";
WebMail.From = "username@gmail.com";

在发送密码丢失说明的页面上,以下代码调用上述设置。但是,它给了我一条消息,表明电子邮件已发送,但收件箱中没有任何内容,这是我做错了吗?

bool passwordSent = false;
var resetToken = "";
var email = Request.Form["email"] ?? Request.QueryString["email"];

// Setup validation
Validation.RequireField("email", "The email address field is required.");

if (IsPost) {
    AntiForgery.Validate();
    // validate email
    bool isValid = true;
    if (Validation.IsValid()) {
        if (WebSecurity.GetUserId(email) > -1 && WebSecurity.IsConfirmed(email)) {
            resetToken = WebSecurity.GeneratePasswordResetToken(email); // Optionally specify an
 expiration date for the token
        } else {
            passwordSent = true; // We don't want to disclose that the user does not exist.
            isValid = false;
        }
    }
    if (isValid) {
        var hostUrl = Request.Url.GetComponents(UriComponents.SchemeAndServer, UriFormat.Unescaped);
        var resetUrl = hostUrl + VirtualPathUtility.ToAbsolute("~/Account/PasswordReset?resetToken=" + HttpUtility.UrlEncode(resetToken));
        WebMail.Send(
            to: email,
            subject: "Please reset your password", 
            body: "Use this password reset token to reset your password. The token is: " + resetToken + @". Visit <a href=""" + HttpUtility.HtmlAttributeEncode(resetUrl) + @""">" + resetUrl + "</a> to reset your password."
        );
        passwordSent = true;
    }
}
}

<hgroup class="title">
<h1>@Page.Title.</h1>
<h2>Use the form below to reset your password.</h2>
</hgroup>

@if (!WebMail.SmtpServer.IsEmpty()) {
<p>
    We will send password reset instructions to the email address associated with your account.
</p>

if (passwordSent) {
    <p class="message-success">
        Instructions to reset your password have been sent to the specified email address.
    </p>
}

<form method="post">
    @AntiForgery.GetHtml()
    @Html.ValidationSummary(excludeFieldErrors: true)

    <fieldset>
        <legend>Password Reset Instructions Form</legend>
        <ol>
            <li class="email">
                <label for="email" @if (!ModelState.IsValidField("email")) {<text>class="error-label"</text>}>Email address</label>
                <input type="text" id="email" name="email" value="@email" disabled="@passwordSent" @Validation.For("email") />
                @Html.ValidationMessage("email")
            </li>
        </ol>
        <p class="form-actions">
            <input type="submit" value="Send instructions" disabled="@passwordSent" />
        </p>
    </fieldset>
</form>
} else {
<p class="message-info">
   Password recovery is disabled for this website because the SMTP server is 
   not configured correctly. Please contact the owner of this site to reset 
   your password.
</p>
}

我已阅读此问题:ASP WebMail: Set up SMTP authentication?,但我不知道如何让表单使用该页面上的设置,而不是 Webmatrix 提供的设置。

【问题讨论】:

    标签: email razor webmatrix


    【解决方案1】:

    上线

    WebMail.SmtpServer = "stmp.gmail.com";
    

    应该是“smtp.gmail.com”吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-23
      • 1970-01-01
      • 2013-02-08
      相关资源
      最近更新 更多