Ask about anything in DailyStory Developer Documentation

Type a question in your own words below. Answers are written from our published articles and cite the ones they came from.

Recently updated

    Dashboard
    Edit Article Logout

    Send Transactional Email


    Sends a transactional email to a single contact. A transactional email ignores all contact opt out preferences and should only be used for transactional communication.

    Personalize using custom fields

    Optionally include a JSON body with properties used to personalize the email.

    { "subject":"My new email subject", // optional to set a subject "from":"hello@example.com", // optional set a from address "confirmation_url":"https://example.com", // optional set a profile field "confirmation_code":"confirmation-38474" // optional set a profile field }

    These fields are then accessible in the email.

    The following fields are reserved fields:

    • subject - (required) set an alternate subject for the email.
    • from - (required) set an alternate from address for the email.
    • body - (required) set the body of the email.
    • preheader- set an alternate preheader for the email.
    • plaintext- set an alternate plaintext for the email.
    • cc - carbon copy recipients. Must be in standard email format. Multiple addresses should be separated with a semi-colon.
    • bcc - blind carbon copy recipient. Must be in standard email format. Multiple addresses should be separated with a semi-colon.
    • reply-to - set the reply-to header of the email. Must be in standard email format. Only a single address is allowed.
    • attachments - include one or more attachments.

    Personalization example

    Hello, your confirmation code is{{profile.confirmation_code}}.

    It's also possible to send a subject or from with a personalization token, for example:

    { "subject":"Your id is {{@profile.custom_id}}" }

    When the email is sent if the contact has a personalization field of "custom_id" it will automatically be inserted.

    Including Attachments

    DailyStory supports email attachments. However, we generally discourage the use and recommend using URLs to resources instead. To enable email attachments for your account, please contact our support team.

    While attachments for marketing emails are disabled by default. Attachments for transactional emails using the transactional email API are supported.

    Adding attachments to a transactional email

    Attachments are sent as part of the JSON message object using the field attachments. However, for various reasons there are multiple steps to properly serialize the attachment information.

    For the purpose of this example we'll use a file called helloworld.txt with the value "Hello world!".

    Convert file to base 64 encoded byte array

    In your code, first convert your file content in to a byte array. Then encode it as a base 64 encoded string. For example:

    SABlAGwAbABvACAAdwBvAHIAbABkACEA

    Is the base 64 encoded byte array for the contents of the helloworld.txt file.

    Build a JSON array of key/value pairs

    Next, create list of JSON objects of key/value pairs where the key in the name of the file and the value is the base 64 encoded byte array:

    {"helloworld.txt":"SABlAGwAbABvACAAdwBvAHIAbABkACEA"}

    For example, to include a second copy of this file:

    {"helloworld.txt":"SABlAGwAbABvACAAdwBvAHIAbABkACEA"},{"world.txt":"SABlAGwAbABvACAAdwBvAHIAbABkACEA"}

    Base 64 encode the string of JSON

    For example, below is the base 64 encoded version of the helloworld.txt single attachment example:

    eyJoZWxsb3dvcmxkLnR4dCI6IlNBQmxBR3dBYkFCdkFDQUFkd0J2QUhJQWJBQmtBQ0VBIn0=

    Finally send the email

    A possible email payload for the API could look like:

    { "from":"hello@example.com", "subject":"Example email with an attachment", "body":"The body of my email. See the attachment below.", "attachments": "eyJoZWxsb3dvcmxkLnR4dCI6IlNBQmxBR3dBYkFCdkFDQUFkd0J2QUhJQWJBQmtBQ0VBIn0K" }
    Query Parameters
    dsidstring
    The dsid of the contact to send to. Either dsid or email is required.
    emailstring
    Email address of the contact to send to. Either dsid or email is required. If the address does not match an existing contact, a new contact is created.
    HTTP Request Examples
    { "from": "hello@example.com", "subject": "Your confirmation code", "body": "<p>Hello, your confirmation code is {{profile.confirmation_code}}.</p>", "plaintext": "Hello, your confirmation code is {{profile.confirmation_code}}.", "confirmation_code": "38474" }
    HTTP Request Parameters
    subjectstringrequired
    Subject line of the email.
    bodystringrequired
    HTML body of the email.
    fromstring
    From address of the email. Defaults to the tenant's no-reply address if omitted.
    preheaderstring
    Optional preheader text shown in the inbox preview.
    plaintextstring
    Optional plaintext version of the email body.
    ccstring
    Carbon-copy email addresses; separate multiple addresses with a semicolon.
    bccstring
    Blind-carbon-copy email addresses; separate multiple addresses with a semicolon.
    reply-tostring
    Single reply-to email address.
    attachmentsstring
    Optional base64-encoded JSON map of filename β†’ base64-encoded file bytes. See the Including Attachments section above.
    (custom personalization fields)string
    Any additional keys in the JSON body are available as {{profile.}} personalization tokens within the subject, from address, or body.
    HTTP Response Examples
    200
    { "Status": true, "Message": "Email Sent", "Response": { "messageid": "20231127164859.ee81700d9b371f25@mg.dailystory.net" } }
    HTTP Response Parameters
    messageidstring
    The Mailgun message id of the sent email. Use this with Get Email's message endpoint to check delivery status later.


    How helpful was this article?

    πŸ‘ or πŸ‘Ž

    Related Articles

    Markdown Version