Change Password on first access using Identity Asp Net Error sending Email

Asked

Viewed 33 times

1

I’m having a problem implementing a feature. The idea is: Make the User change password at first access(Since the user is created by someone else).

How I’m using the Identity, I took logic of the method Forgotpassword and put inside the Method Register (Both of Controller Account), so when the administrator creates a new user, an email is already sent to the user with the link to "change the password", so he already changes password and enters the System. The problem that when he will send the e-mail it gives the following error in the method that sends e-mail:

System.Net.Mail.Smtpexception: 'The SMTP server requires a secure connection or the client has not been authenticated.

In the method that sends Identity email (public task Sendasync(Identitymessage message) )

This is the Error Giving Method:

public Task SendAsync(IdentityMessage message)
{
    // cria uma mensagem
    MailMessage mensagemEmail = new MailMessage("[email protected]", message.Destination, "Confirmação de Cadastro", message.Body);

    SmtpClient client = new SmtpClient("smtp.gmail.com", 587);
    client.EnableSsl = true;
    NetworkCredential cred = new NetworkCredential("[email protected]", "senha123");
    client.Credentials = cred;

    // inclui as credenciais
    client.UseDefaultCredentials = false;

    // envia a mensagem
    client.Send(mensagemEmail);

    // Plug in your email service here to send an email.
    return Task.FromResult(0);
}

Someone who can help me?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.