sendTemplatedEmail method

Future<SendTemplatedEmailResponse> sendTemplatedEmail({
  1. required Destination destination,
  2. required String source,
  3. required String template,
  4. required String templateData,
  5. String? configurationSetName,
  6. List<String>? replyToAddresses,
  7. String? returnPath,
  8. String? returnPathArn,
  9. String? sourceArn,
  10. List<MessageTag>? tags,
  11. String? templateArn,
})

Composes an email message using an email template and immediately queues it for sending.

To send email using this operation, your call must meet the following requirements:

  • The call must refer to an existing email template. You can create email templates using the CreateTemplate operation.
  • The message must be sent from a verified email address or domain.
  • If your account is still in the Amazon SES sandbox, you may only send to verified addresses or domains, or to email addresses associated with the Amazon SES Mailbox Simulator. For more information, see Verifying Email Addresses and Domains in the Amazon SES Developer Guide.
  • The maximum message size is 10 MB.
  • Calls to the SendTemplatedEmail operation may only include one Destination parameter. A destination is a set of recipients that receives the same version of the email. The Destination parameter can include up to 50 recipients, across the To:, CC: and BCC: fields.
  • The Destination parameter must include at least one recipient email address. The recipient address can be a To: address, a CC: address, or a BCC: address. If a recipient email address is invalid (that is, it is not in the format UserName@\[SubDomain.\]Domain.TopLevelDomain), the entire message is rejected, even if the message contains other recipients that are valid.

Implementation

Future<SendTemplatedEmailResponse> sendTemplatedEmail({
  required Destination destination,
  required String source,
  required String template,
  required String templateData,
  String? configurationSetName,
  List<String>? replyToAddresses,
  String? returnPath,
  String? returnPathArn,
  String? sourceArn,
  List<MessageTag>? tags,
  String? templateArn,
}) async {
  final $request = <String, String>{
    for (var e1 in destination.toQueryMap().entries)
      'Destination.${e1.key}': e1.value,
    'Source': source,
    'Template': template,
    'TemplateData': templateData,
    if (configurationSetName != null)
      'ConfigurationSetName': configurationSetName,
    if (replyToAddresses != null)
      if (replyToAddresses.isEmpty)
        'ReplyToAddresses': ''
      else
        for (var i1 = 0; i1 < replyToAddresses.length; i1++)
          'ReplyToAddresses.member.${i1 + 1}': replyToAddresses[i1],
    if (returnPath != null) 'ReturnPath': returnPath,
    if (returnPathArn != null) 'ReturnPathArn': returnPathArn,
    if (sourceArn != null) 'SourceArn': sourceArn,
    if (tags != null)
      if (tags.isEmpty)
        'Tags': ''
      else
        for (var i1 = 0; i1 < tags.length; i1++)
          for (var e3 in tags[i1].toQueryMap().entries)
            'Tags.member.${i1 + 1}.${e3.key}': e3.value,
    if (templateArn != null) 'TemplateArn': templateArn,
  };
  final $result = await _protocol.send(
    $request,
    action: 'SendTemplatedEmail',
    version: '2010-12-01',
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    resultWrapper: 'SendTemplatedEmailResult',
  );
  return SendTemplatedEmailResponse.fromXml($result);
}