如何在主机上使用mvcMailer发送邮件

时间:2015-08-29 16:57:29

标签: asp.net-mvc mvcmailer

如何在主机www.mywindowshosting.com上使用mvcMailer发送邮件?

我使用以下代码:

UserMailer类:

  public class UserMailer : MailerBase, IUserMailer
    {
        public UserMailer()
        {
            MasterName = "_Layout";
        }

        public MvcMailMessage ForgetPassword(EmailForgetPasswordViewModel forgetPasswordViewModel)
        {
            ViewData.Model = forgetPasswordViewModel;
            return Populate(x =>
            {
                x.BodyTransferEncoding = System.Net.Mime.TransferEncoding.Base64;
                x.BodyEncoding = Encoding.UTF8;
                x.Subject = forgetPasswordViewModel.Subject;
                x.ViewName = forgetPasswordViewModel.ViewName;
                x.To.Add(forgetPasswordViewModel.To);
            });
        }
    }

界面:

 public interface IUserMailer
    {
        MvcMailMessage ForgetPassword(EmailForgetPasswordViewModel forgetPasswordViewModel);
    }

行动:

[HttpPost]
[AllowAnonymous]
[MyValidateAntiForgeryToken]
public async Task<JsonResult> ForgotPassword(ForgetPasswordViewModel model)
{
    if (ModelState.IsValid)
    {
        await _userMailer.ForgetPassword(new EmailForgetPasswordViewModel
         {
             To = model.Email,
             Url = callbackUrl
         }).SendAsync();
        return SuccessSendMail();
    }
    return ModelState.GetListOfErrors();
}

输出:Request was sent successfully。输出正确但不发送电子邮件。

Note :代码在localhost上正常运行,系统会发送电子邮件。但是当项目在www.mywindowshosting.com上发布时,不会发送电子邮件但输出:Request was sent successfully

更新:

    <smtp from="myMail@gmail.com">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="myMail@gmail.com" password="myPassword" />
    </smtp>

0 个答案:

没有答案