MVC 4 Email.Send Error

301 views Asked by At

I am using Postal to send a confirmation email to a new registered user. But it gets caught in when it hits email.send();. Here is my controller code:

public ActionResult Register(RegisterModel model)
    {
        if (ModelState.IsValid)
        {
            // Attempt to register the user
            try
            {
                string confirmationToken =  
                    WebSecurity.CreateUserAndAccount(model.UserName, model.Password, 
                                new { model.Email}, true);

                dynamic email = new Email("RegEmail");
                email.To = model.Email;
                email.UserName = model.UserName;
                email.ConfirmationToken = confirmationToken;
                email.HostLocation = Request.Url.Host + ':' + Request.Url.Port;

                email.Send();

                return RedirectToAction("RegisterStepTwo", "Account");
                //return RedirectToAction("Index", "Festival");
            }
            catch (MembershipCreateUserException e)
            {
                ModelState.AddModelError("", ErrorCodeToString(e.StatusCode));
            }
        }

        // If we got this far, something failed, redisplay form
        return View(model);
    }

Does anyone know the problem?

0

There are 0 answers