anchor.diff: -[[email-ext-plugin-recipes]]
  -= email-ext-plugin Recipes
  +[[email-extension-recipes]]
  += Email Extension Recipes
   :toc: macro
   :toc-title:
   ifdef::env-github[]
  
positive.code: 
  Post-send scripts are available starting with version 2.41.
  
  === Use rewritten Message-ID from AWS SES for In-Reply-To header
  
  The Amazon Simple Email Service (https://aws.amazon.com/ses/[AWS SES])
  rewrites the Message-ID header of outgoing emails. That means subsequent
  failure/success notifications will not be in the same thread, because
  they reference a non-existing message id in the In-Reply-To header.
  
  The rewritten message id is returned as last message of the SMTP
  transaction, e.g.
  
   250 Ok <00000123456abcde-1234abcd-abcd-1234-1234-1234abcd1234-000000@eu-west-1.amazonses.com>
  
  The following post-send script fetches the rewritten message id for
  later correct In-Reply-To headers:
  
  *Use AWS SES Message-ID*
  
  [source,groovy]
  ----
  import com.sun.mail.smtp.SMTPTransport;
  import java.util.regex.Matcher;
  import java.util.regex.Pattern;
  import hudson.plugins.emailext.ExtendedEmailPublisherDescriptor;
  
  String smtpHost = props.getProperty("mail.smtp.host", "");
  String awsRegex = "^email-smtp\\.([a-z0-9-]+)\\.amazonaws\\.com\$";
  
negative.code: }
  
  recipients = msg.getRecipients(javax.mail.Message.RecipientType.TO)
  filtered = recipients.findAll { addr -> includedInWhitelist(addr) > 0 }
  msg.setRecipients(javax.mail.Message.RecipientType.TO, filtered as javax.mail.Address[])
  ----
  
  