Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email verification #195

Open
Mustimain opened this issue Mar 26, 2023 · 7 comments
Open

Email verification #195

Mustimain opened this issue Mar 26, 2023 · 7 comments

Comments

@Mustimain
Copy link

How can I send an email for email verification? Please help me

@domsse
Copy link

domsse commented Mar 28, 2023

Hey @Mustimain, I recently asked myself the same question when I started a new project. Have you already found a solution to this or is the question still open?

@Mustimain
Copy link
Author

still open unfortunately i couldn't find a solution

@domsse
Copy link

domsse commented Apr 1, 2023

@Mustimain i have now sat down to the problem and complete the email verification via a small detour.
I use the Nuget: "NuGet\Install-Package FirebaseAdmin -Version 2.3.0" in my Project to create an Email Verification Link.

I created a FirebaseAdmin.FirebaseApp after the registration and created the link based on the email from the user. Afterwards I deleted the FirebaseApp instance.
(Could certainly be kept for further functions from the FirebaseAdmin SDK).

public async Task RegistrationUser(string email, string password, string username)
{
     UserCredential = await authViewModel.RegisterUserWithEmail(email, password, username);
     User = UserCredential.User;

     FirebaseApp.Create(new AppOptions()
     {
          Credential = GoogleCredential.FromFile(filePath)
     });

     var link = await FirebaseAuth.DefaultInstance.GenerateEmailVerificationLinkAsync(email);

     FirebaseApp.DefaultInstance.Delete();

     await SendEmailVerificationAsync(link, email, username);
}

Afterwards I created a SmtpClient and sent an email to the user. This worked fine for me. (So you can also design the email according to your own wishes, which was also my wish).

Let me know if I could help you a little bit with my detour.
(Sorry for my funny english, english is not my main language. ^^)

@Mustimain
Copy link
Author

@domsse thank you for your help solved my problem

@koddek
Copy link

koddek commented Jul 19, 2023

@domsse @Mustimain were you working on a .NET MAUI app? I can't get SmtpClient to work on .NET MAUI.

@domsse
Copy link

domsse commented Jul 21, 2023

Hi @koddek I have been working with a .NET MAUI application. I used normal SmtpClient (using System.Net.Mail) with own credential. What did you do? Do you have a sample code for me where it doesn't work?

@koddek
Copy link

koddek commented Jul 21, 2023

Hi @domsse, thanks for your reply

What did you do? Do you have a sample code for me where it doesn't work?

I created a clean .NET MAUI app. Both the XAML and Blazor versions.

  • Then add a button.
  • Then fill out this and run this method when the button is clicked.
public void SendEmailUsingMicrosoftSmtp()
{
    var fromName = "Jon";
    var fromEmail = "EMAIL@outlook.com";
    var fromPass = "EMAILPASSWORD";

    var toName = "Jane";
    var toEmail = "JANEEMAIL@outlook.com";

    var message = new MimeMessage();
    message.From.Add(new MailboxAddress(fromName, fromEmail));
    message.To.Add(new MailboxAddress(toName, toEmail));
    message.Subject = "Hello from Microsoft SMTP";

    var bodyBuilder = new BodyBuilder
    {
        HtmlBody = "This is an email sent via Microsoft SMTP with SSL on port 587."
    };

    message.Body = bodyBuilder.ToMessageBody();

    using var client = new SmtpClient();
    client.Connect("smtp.office365.com", 587, SecureSocketOptions.StartTls);
    // client.Connect("smtp.office365.com", 465, SecureSocketOptions.SslOnConnect);
    client.Authenticate(fromEmail, fromPass);
    client.Send(message);
    client.Disconnect(true);
}

This code works on Blazor Server, but not on Webassembly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants