Open Mustimain opened 1 year ago
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?
still open unfortunately i couldn't find a solution
@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. ^^)
@domsse thank you for your help solved my problem
@domsse @Mustimain were you working on a .NET MAUI app? I can't get SmtpClient to work on .NET MAUI.
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?
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 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.
How can I send an email for email verification? Please help me