Blazor Server B2C Project with additional EmailSender

admin@padis.ch 1 Reputation point
2022-09-07T09:40:30.377+00:00

Hello, in a Blazor Server B2C (LogIn) Project i'd like to add a additional email sender. Not for Login but for email info e.g. after a user saved a new input form.
I tried it with SendGrid which works fine in a non B2C Project but not in the B2C Project. My question, is SendGrid the right set-up for a B2C Project or not?
How d I config and set this up? Many thanks for your support, marcel

Blazor
Blazor
A free and open-source web framework that enables developers to create web apps using C# and HTML being developed by Microsoft.
1,349 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Marco S. Junior 26 Reputation points
    2023-05-25T10:54:45.8933333+00:00

    You can create a custom property called AdditionalEmailSender or a name of your choice in azure B2C...

    I will put here a snipped of my real blazor app that's uses sendgrid so you can use it as guidance...

    using SendGrid;
    using SendGrid.Helpers.Mail;
    namespace MyProj.Classes
    {
        public class SendMail
        {
    
            public async Task SendPassCode(string code, string email) {
                var apiKey = "The Key";
                var client = new SendGridClient(apiKey);
                var from = new EmailAddress("from@domain.com ", "Display Name");
                var subject = "Your Pass Code";
                var to = new EmailAddress(email); // put your email in a variable after you got the account details
                var plainTextContent = $"Code:{code}";
                var htmlContent = $"<strong>Code:</strong> {code}";
                var msg = MailHelper.CreateSingleEmail(from, to, subject, plainTextContent, htmlContent);
                var response = await client.SendEmailAsync(msg).ConfigureAwait(false);
            }
        }
    }
    
    0 comments No comments