Tips & Tricks: Scheduling email delivery

It's always fun chatting with customers about what they like about Mailgun (and what they'd like to see improved ).  We spoke to a customer recently who LOVED that they could schedule delivery of their messages at a specific time in the future.  Who knew that this little feature would mean so much to some customers.  Today's blog is about how it works, in case it's not already part of your workflow.

Scheduling email delivery at a particular time

Some emails needs to be delivered as quickly as possible: error reports, password resets, and welcome emails, for example.  Others, however, need to arrive at a particular time to be most effective.  For instance, a local restaurant might want to send their daily lunch specials everday at 11 am, so people get it right when their stomachs are starting to growl, but before they've chosen a restaurant.  The same email received at 4pm is a lot less useful!

Here are some other times that scheduling messages makes sense:

[list type="clock"]

  • You want your emails delivered to recipients worldwide at a specific time in their local time zone
  • You want to send an upgrade offer 48 hours after a customer signups for a free trial
  • You're leaving on vacation but still want your monthly release notes delivered to your users while you are relaxing on a beach

[/list]

Mailgun makes this easy with the o:deliverytime parameter which is available when you send email through our API or  SMTP.

Sample code to schedule message delivery

o:deliverytime is simply a parameter that you specify when sending Mailgun your message.  It is set just like to:, from: , subject: and all the other parameters of your email.

Here is what the code could look like to send a single email:

def send_scheduled_message():  
    return requests.post(
        "https://api.mailgun.net/v2/samples.mailgun.org/messages",
        auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
        data={"from": "George <me@samples.mailgun.org>",
              "to": "sergeyo@profista.com",
              "subject": "Hello, from the future",
              "text": "No one else is wearing a silver jumpsuit.  I feel kinda out of place.",
              "o:deliverytime": "Fri, 25 May 2020 23:10:10 -0000"})

If you want to send different recipients the same email at different times (say at 9am on the East and West Coast), you can using Batch Sending to send up to 1000 recipients in a single API call.  Just define the delivery time for each batch when you send it as above.  And remember that with Batch Sending, you can use Recipient Variables to personalize each email in the batch with things like First Name, Order Amount, even targeted offers.  You can read more about adding Recipient Variables to your emails here.

When scheduling delivery, dates need to be strings encoded according to  RFC 2822.  This format is native to JavaScript and is also supported by most programming languages out of the box:

'Thu, 13 Oct 2011 18:02:00 GMT'

Finally, there are a lot of factors that affect delivery time including the email content itself which influences how likely ESPs like Gmail and Yahoo are to flag it as spam and delay or prevent delivery.  Mailgun will make every effort to deliver your emails as close to your specified time as possible, but can't guarantee delivery at a specific time.  In addition to using o:deliverytime,  following our Email Best Practices guide is the best way to make sure your emails get delivered in a timely manner.

Happy emailing,

The Mailgunners

 

comments powered by Disqus

Mailgun Get posts by email

Like what you're reading? Get these posts delivered to your inbox.

No spam, ever.