0

When i am registering a new user to my site, the code is supposed to generate an email for the user to then confirm, but no email is being sent. Please help

using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.Owin;
using Owin;
using WebAppForms.Models;

namespace WebAppForms.Account
{
public partial class Register : Page
{
    protected void CreateUser_Click(object sender, EventArgs e)
    {
        var manager = 
Context.GetOwinContext().GetUserManager<ApplicationUserManager>();
        var signInManager = 
Context.GetOwinContext().Get<ApplicationSignInManager>();
        var user = new ApplicationUser() { UserName = Email.Text, Email = 
Email.Text };
        IdentityResult result = manager.Create(user, Password.Text);
        if (result.Succeeded)
        {

            string code = manager.GenerateEmailConfirmationToken(user.Id);
            string callbackUrl = 
IdentityHelper.GetUserConfirmationRedirectUrl(code, user.Id, Request);
            manager.SendEmail(user.Id, "Confirm your account", "Please 
confirm your account by clicking <a href=\"" + callbackUrl + 
"\">here</a>.");

            signInManager.SignIn( user, isPersistent: false, 
rememberBrowser: false);

IdentityHelper.RedirectToReturnUrl(Request.QueryString["ReturnUrl"], 
Response);
        }
        else 
        {
            ErrorMessage.Text = result.Errors.FirstOrDefault();
        }
    }
}
}

I followed the Microsoft tutorial, but it still doesnt work

wazz
  • 4,953
  • 5
  • 20
  • 34
CyberCube
  • 159
  • 3
  • 11
  • Possible duplicate of [UserManager SendEmailAsync No Email Sent](https://stackoverflow.com/questions/31523276/usermanager-sendemailasync-no-email-sent) – Matt M Jan 02 '18 at 20:57
  • Make sure your SMTP configuration is correctly specified in web config file. – Sunil Jan 03 '18 at 10:34
  • "doesn't work" is not telling us anything about the problem you're getting. What error are you getting? Have you set up an email account for sending those emails? – derloopkat Jan 03 '18 at 10:45
  • Hi Derloopkat, i dont get an error, but then i didnt set up an email account either. Do i create a gmail account and then reference those details somewhere? – CyberCube Jan 03 '18 at 11:06

0 Answers0