sendEmail method

Future<void> sendEmail({
  1. required String token,
  2. required ServerpodCloudEmailType emailType,
  3. required String email,
  4. required String projectName,
  5. required String authCode,
})

Sends a transactional email through the Serverpod Cloud email service.

Throws a ServerpodCloudEmailException if the service does not respond with a 200 status code.

Implementation

Future<void> sendEmail({
  required final String token,
  required final ServerpodCloudEmailType emailType,
  required final String email,
  required final String projectName,
  required final String authCode,
}) async {
  final response = await _httpClient
      .post(
        Uri.parse('$baseUrl/api/email/send'),
        headers: const {'Content-Type': 'application/json'},
        body: jsonEncode({
          'token': token,
          'emailType': emailType.wireValue,
          'email': email,
          'projectName': projectName,
          'authCode': authCode,
        }),
      )
      .timeout(timeout);

  if (response.statusCode == 200) {
    return;
  }

  throw ServerpodCloudEmailException(
    response.statusCode,
    _tryParseError(response.body),
  );
}