• Email DIY

Tips & Tricks: Scheduling Email Delivery

Mailgun Team
5 min read
featured

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:

  • 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

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:

1 def send_scheduled_message():
2 return requests.post(
3 "https://api.mailgun.net/v2/samples.mailgun.org/messages",
4 auth=("api", "key-3ax6xnjp29jd6fds4gc373sgvjxteol0"),
5 data={"from": "George <me@samples.mailgun.org>",
6 "to": "sergeyo@profista.com",
7 "subject": "Hello, from the future",
8 "text": "No one else is wearing a silver jumpsuit. I feel kinda out of place.",
9 "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 2822This 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

DELIVERABILITY SERVICES

Learn about our Deliverability Services

Looking to send a high volume of emails? Our email experts can supercharge your email performance. See how we've helped companies like Lyft, Shopify, Github increase their email delivery rates to an average of 97%.

Learn More

Last updated on May 17, 2021

  • Related posts
  • Recent posts
  • Top posts
View all

Always be in the know and grab free email resources!

No spam, ever. Only musings and writings from the Mailgun team.

By sending this form, I agree that Mailgun may contact me and process my data in accordance with its Privacy Policy.

sign up
It's easy to get started. And it's free.
See what you can accomplish with the world's best email delivery platform.
Sign up for Free