ledgeJumper
ledgeJumper

Reputation: 3630

Using MVCMailer in asp.net MVC4 application, keep getting error on email send

I am using MVCMailer as my email harness for all the many email this web app will be sending. Getting emails sent is simple enough, but I can't get it working while I am testing on localhost.

On the site I set it up like it says you need to. My web config has this in it:

<system.net>
    <mailSettings>
      <!-- Method#1: Configure smtp server credentials -->
      <smtp from="[email protected]">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="pass" />
      </smtp>
    </mailSettings>
</system.net>

I am setting this on top of my Controller:

private IUserMailer _userMailer = new UserMailer();
public IUserMailer UserMailer
{
    get { return _userMailer; }
    set { _userMailer = value; }
}

And this is where I am calling the 'Send' Method to test the welcome message (inside an ActionResult Method):

_userMailer.Welcome(model.EmailAddress, model.FirstName + " " + model.LastName).Send();

I believe that I did not miss anything in the tutorial linked about, but when stepping through the code I get this error:

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. 

A few questions I guess:

  1. Is there a setting I can do to make this run?
  2. If I have 2-Factor auth on my gmail, is that going to interfere?
  3. Am I missing something so obvious I will want to delete this question?

Thanks!

EDIT

  1. The password was a joke, I am not that dumb, give me some credit.. :)

The Send() implementation does this (its built into MVC mailer):

public virtual MvcMailMessage Welcome(string email, string fullName)
{
//ViewBag.Data = someObject;
return Populate(x =>
{
    x.Subject = "Welcome to eTrail Cub Tracking " + fullName;
    x.ViewName = "Welcome";
    x.To.Add(email);
});
}

Upvotes: 2

Views: 3876

Answers (2)

harrison
harrison

Reputation: 79

perhaps you are missing something untowards: smtp.Send(x);

try:

public virtual MvcMailMessage Welcome(string email, string fullName)
{

    //ViewBag.Data = someObject;

    return Populate(x =>
    {
        x.Subject = "Welcome to eTrail Cub Tracking " + fullName;
        x.ViewName = "Welcome";
        x.To.Add(email);
        stmp.send(x);
    });
}

Upvotes: 0

Khalid Abuhakmeh
Khalid Abuhakmeh

Reputation: 10839

Not sure if this is your issue, but it looks like you forgot to setup the default delivery method on your config.

You have

<system.net>
    <mailSettings>
      <!-- Method#1: Configure smtp server credentials -->
      <smtp from="[email protected]">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="pass" />
      </smtp>
    </mailSettings>
</system.net>

Try :

<system.net>
    <mailSettings>
      <!-- Method#1: Configure smtp server credentials -->
      <smtp from="[email protected]" deliveryMethod="Network">
        <network enableSsl="true" host="smtp.gmail.com" port="587" userName="[email protected]" password="pass" />
      </smtp>
    </mailSettings>
</system.net>

I would also try to just use the SmtpClient directly in a code sample without MvcMailer and see if the issue is just a configuration one.

Upvotes: 2

Related Questions