gmailRelaySaslXoauth2 function

SmtpServer gmailRelaySaslXoauth2(
  1. String userEmail,
  2. String accessToken

Send through GSuite gmail relay with SASL XOAUTH2 authentication.

This requires that the G Suite SMTP relay service is enabled by the GSuite administrator. For more information see: Send email from a printer, scanner, or app.

This requires an accessToken for userEmail with the OAuth2 scope: This can be obtained in many differnet ways, one could add an application to the GSuite account and have users grant access, or one could use domain-wide delegation to obtain a service-account that can impersonate any GSuite user for the given domain with the, and then use said service account to obtain an accessToken impersonating a GSuite user.


SmtpServer gmailRelaySaslXoauth2(
  String userEmail,
  String accessToken,
) =>
      xoauth2Token: _formatXoauth2Token(userEmail, accessToken),
      ssl: true,
      port: 465,