NullPointerException when trying to send email from custom event handler

Hi all. I am currently running Keycloak 12.0.4 on a Windows 10 Enterprise dev machine.

I am implementing a custom EventListenerProvider that detects when a new user is created in the admin and emails the new user a welcome email with some specific information. I have the event listener working fine, the problem is when I call send on the DefaultEmailSenderProvider, I get a NPE like this:

2022-03-16 09:05:07,317 ERROR [com.company.keycloak.events.RegistrationEmailEventListenerProvider] (default task-2) Failed to send email: org.keycloak.email.EmailException
: java.lang.NullPointerException
at org.keycloak.email.DefaultEmailSenderProvider.send(DefaultEmailSenderProvider.java:153)
at com.company.keycloak.events.RegistrationEmailEventListenerProvider.sendInvitationEmail(RegistrationEmailEventListenerProvider.java:160)
at com.company.keycloak.events.RegistrationEmailEventListenerProvider.onEvent(RegistrationEmailEventListenerProvider.java:83)

Caused by: java.lang.NullPointerException
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:769)
at javax.mail.internet.InternetAddress.parse(InternetAddress.java:728)
at javax.mail.internet.InternetAddress.(InternetAddress.java:95)
at org.keycloak.email.DefaultEmailSenderProvider.send(DefaultEmailSenderProvider.java:150)

This is the relevant part of the code that does the sending:

public class RegistrationEmailEventListenerProvider implements EventListenerProvider
{
   private final KeycloakSession session;
   private final RealmProvider model;

   public RegistrationEmailEventListenerProvider(KeycloakSession session) {
      this.session = session;
      this.model = session.realms();
  }

  @Override
  public void onEvent(AdminEvent event, boolean includeRepresentation)
  {
    if (OperationType.CREATE.equals(event.getOperationType()) && ResourceType.USER.equals(event.getResourceType()))
    {
      RealmModel realm = this.model.getRealm(event.getRealmId());
      // did not include this method implementation but it pulls email address out of the json.. log confirms it is working
      String emailAddress = getEmailFromRepresentation(event.getRepresentation()); 
      log.info("Parsed email from json: [" + emailAddress + "]");

      sendInvitationEmail(emailAddress);
    }
  }

  private void sendInvitationEmail(String emailAddress)
  {
    // REMOVED - pulled email plain and html content into variables emailPlainContent and emailHtmlContent

    // send the email
    DefaultEmailSenderProvider senderProvider = new DefaultEmailSenderProvider(session);

    Map<String, String> smtpConfig = session.getContext().getRealm().getSmtpConfig();

    AdminUser user = new AdminUser();
    user.setEmail(emailAddress);
    
    try
    {
      senderProvider.send(smtpConfig, user, "ConnectMyHealth - welcome new user!", emailPlainContent.toString(),
          emailHtmlContent);
    }
    catch (EmailException e)
    {
      log.error("Failed to send email", e);
    }

  }
}

I have configured the email settings in Keycloak both on the master realm and on the realm I have created for the application, and I used the test button on both pages to ensure that mail was being sent successfully. One thing that wasn’t clear to me was where it was getting email address from, because if that was null/empty, I would get the exact exception that I am getting. But as you can see I log the email address to ensure I am getting it correctly out of the event json, and I am. And I download the source for Keycloak from github and I know that it pulls the email out of the user object that is passed in, so the setup I have should work. Any insight would be greatly appreciated.