Method: Mandrill::Messages#send_template

Defined in:
lib/mandrill/api.rb

#send_template(template_name, template_content, message, async = false, ip_pool = nil, send_at = nil) ⇒ Array

Send a new transactional message through Mandrill using a template

Parameters:

  • template_name (String)

    the immutable name or slug of a template that exists in the user’s account. For backwards-compatibility, the template name may also be used but the immutable slug is preferred.

  • template_content (Array)

    an array of template content to send. Each item in the array should be a struct with two keys - name: the name of the content block to set the content for, and content: the actual content to put into the block

    • Hash

      template_content[] the injection of a single piece of content into a single editable region

      - [String] name the name of the mc:edit editable region to inject into
      - [String] content the content to inject
      
  • message (Hash)

    the other information on the message to send - same as /messages/send, but without the html content

    • String

      html optional full HTML content to be sent if not in template

    • String

      text optional full text content to be sent

    • String

      subject the message subject

    • String

      from_email the sender email address.

    • String

      from_name optional from name to be used

    • Array

      to an array of recipient information.

      - [Hash] to[] a single recipient's information.
          - [String] email the email address of the recipient
          - [String] name the optional display name to use for the recipient
          - [String] type the header type to use for the recipient, defaults to "to" if not provided
      
    • Hash

      headers optional extra headers to add to the message (most headers are allowed)

    • Boolean

      important whether or not this message is important, and should be delivered ahead of non-important messages

    • Boolean

      track_opens whether or not to turn on open tracking for the message

    • Boolean

      track_clicks whether or not to turn on click tracking for the message

    • Boolean

      auto_text whether or not to automatically generate a text part for messages that are not given text

    • Boolean

      auto_html whether or not to automatically generate an HTML part for messages that are not given HTML

    • Boolean

      inline_css whether or not to automatically inline all CSS styles provided in the message HTML - only for HTML documents less than 256KB in size

    • Boolean

      url_strip_qs whether or not to strip the query string from URLs when aggregating tracked URL data

    • Boolean

      preserve_recipients whether or not to expose all recipients in to “To” header for each email

    • Boolean

      view_content_link set to false to remove content logging for sensitive emails

    • String

      bcc_address an optional address to receive an exact copy of each recipient’s email

    • String

      tracking_domain a custom domain to use for tracking opens and clicks instead of mandrillapp.com

    • String

      signing_domain a custom domain to use for SPF/DKIM signing instead of mandrill (for “via” or “on behalf of” in email clients)

    • String

      return_path_domain a custom domain to use for the messages’s return-path

    • Boolean

      merge whether to evaluate merge tags in the message. Will automatically be set to true if either merge_vars or global_merge_vars are provided.

    • String

      merge_language the merge tag language to use when evaluating merge tags, either mailchimp or handlebars

    • Array

      global_merge_vars global merge variables to use for all recipients. You can override these per recipient.

      - [Hash] global_merge_vars[] a single global merge variable
          - [String] name the global merge variable's name. Merge variable names are case-insensitive and may not start with _
          - [Mixed] content the global merge variable's content
      
    • Array

      merge_vars per-recipient merge variables, which override global merge variables with the same name.

      - [Hash] merge_vars[] per-recipient merge variables
          - [String] rcpt the email address of the recipient that the merge variables should apply to
          - [Array] vars the recipient's merge variables
              - [Hash] vars[] a single merge variable
                  - [String] name the merge variable's name. Merge variable names are case-insensitive and may not start with _
                  - [Mixed] content the merge variable's content
      
    • Array

      tags an array of string to tag the message with. Stats are accumulated using tags, though we only store the first 100 we see, so this should not be unique or change frequently. Tags should be 50 characters or less. Any tags starting with an underscore are reserved for internal use and will cause errors.

      - [String] tags[] a single tag - must not start with an underscore
      
    • String

      subaccount the unique id of a subaccount for this message - must already exist or will fail with an error

    • Array

      google_analytics_domains an array of strings indicating for which any matching URLs will automatically have Google Analytics parameters appended to their query string automatically.

    • Array, String

      google_analytics_campaign optional string indicating the value to set for the utm_campaign tracking parameter. If this isn’t provided the email’s from address will be used instead.

    • Array

      metadata metadata an associative array of user metadata. Mandrill will store this metadata and make it available for retrieval. In addition, you can select up to 10 metadata fields to index and make searchable using the Mandrill search api.

    • Array

      recipient_metadata Per-recipient metadata that will override the global values specified in the metadata parameter.

      - [Hash] recipient_metadata[] metadata for a single recipient
          - [String] rcpt the email address of the recipient that the metadata is associated with
          - [Array] values an associated array containing the recipient's unique metadata. If a key exists in both the per-recipient metadata and the global metadata, the per-recipient metadata will be used.
      
    • Array

      attachments an array of supported attachments to add to the message

      - [Hash] attachments[] a single supported attachment
          - [String] type the MIME type of the attachment
          - [String] name the file name of the attachment
          - [String] content the content of the attachment as a base64-encoded string
      
    • Array

      images an array of embedded images to add to the message

      - [Hash] images[] a single embedded image
          - [String] type the MIME type of the image - must start with "image/"
          - [String] name the Content ID of the image - use <img src="cid:THIS_VALUE"> to reference the image in your HTML content
          - [String] content the content of the image as a base64-encoded string
      
  • async (Boolean) (defaults to: false)

    enable a background sending mode that is optimized for bulk sending. In async mode, messages/send will immediately return a status of “queued” for every recipient. To handle rejections when sending in async mode, set up a webhook for the ‘reject’ event. Defaults to false for messages with no more than 10 recipients; messages with more than 10 recipients are always sent asynchronously, regardless of the value of async.

  • ip_pool (String) (defaults to: nil)

    the name of the dedicated ip pool that should be used to send the message. If you do not have any dedicated IPs, this parameter has no effect. If you specify a pool that does not exist, your default pool will be used instead.

  • send_at (String) (defaults to: nil)

    when this message should be sent as a UTC timestamp in YYYY-MM-DD HH:MM:SS format. If you specify a time in the past, the message will be sent immediately. An additional fee applies for scheduled email, and this feature is only available to accounts with a positive balance.

Returns:

  • (Array)

    of structs for each recipient containing the key “email” with the email address, and details of the message status for that recipient

    • Hash

      return[] the sending results for a single recipient

      - [String] email the email address of the recipient
      - [String] status the sending status of the recipient - either "sent", "queued", "rejected", or "invalid"
      - [String] reject_reason the reason for the rejection if the recipient status is "rejected" - one of "hard-bounce", "soft-bounce", "spam", "unsub", "custom", "invalid-sender", "invalid", "test-mode-limit", or "rule"
      - [String] _id the message's unique id
      


919
920
921
922
# File 'lib/mandrill/api.rb', line 919

def send_template(template_name, template_content, message, async=false, ip_pool=nil, send_at=nil)
    _params = {:template_name => template_name, :template_content => template_content, :message => message, :async => async, :ip_pool => ip_pool, :send_at => send_at}
    return @master.call 'messages/send-template', _params
end