testStack
testStack

Reputation: 375

how to send mail with mvcMailer on host

how to send mail with mvcMailer on host www.mywindowshosting.com ?

I am using the following code :

UserMailer class :

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

interface :

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

action :

[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();
}

output : Request was sent successfully. The output is correct but does not send email.

Note : The code works correctly on the localhost And e-mail will be sent. but When the project is publish on www.mywindowshosting.com E-mail not be sent but output : Request was sent successfully

update :

    <smtp from="[email protected]">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="myPassword" />
    </smtp>

Upvotes: 0

Views: 194

Answers (0)

Related Questions