Send Duplicacy Backup Notifications with Mailgun

Duplicacy to mailgun email automation

I'm setting up Duplicacy Backup after a drive failed during a lightning storm, and after evaluating backup software options. Backups are no good if they fail without telling you!

Here's how I set it up Mailgun to send the notifications of backup success and failure.

Duplicacy lets you send SMTP notifications after scheduled backups, by ticking the 'Send email after completion' checkbox.

Nightly backup every night at 2:00am screenshot of Duplicacy. There's a checkbox: "Send email after completion".
Screenshot of Duplicacy Web UI

Usually I'd register a throwaway GMail account for sending email from automated bots, but saspus@ on the Duplicacy forums suggested:

It’s best not to use Gmail for sending automated email; especially if it involves exporting credentials that provide full access to your google account and storing them pretty much plaintext within the service that has no business accessing your gmail account in the first place. This not only defeats any MFA you might have there but is also likely against googles TOS.
Especially when dedicated services for sending this type of transactional emails are readily available (E.g. mail gun, Amazon SES, etc).

They're right, it's annoying registering throwaway GMail accounts: you have to set up security questions and backup accounts and the account might get closed as spam. So let's try Mailgun instead.

Mailgun has a free indefinitely-long trial tier, which looks sufficient:

Trial starting at $0/month, 5000 emails/month included
5k should be enough for me sending one email a day.

Sign up, verify your email, validate your phone number by SMS.

Then you have to add yourself as an 'authorized recipient'. I had trouble finding this, it's under "Sending > Overview > Authorized Recipients".

Screenshot of Mailgun. left nav: sending, overview. right side: Authorized recipients, textbox to enter email.
Sending > Overview > Authorized Recipients

Free trial accounts can only send to these verified recipients. You get 5 free recipients; I only need one.

Then click 'SMTP', as Duplicacy only does SMTP sending, not HTTP-with-API-key sending:

Screenshot of Mailgun. SMTP. The easiest way to send email. Select

Then create credentials for Duplicacy. You could just use the default sender credentials, but just in case I use this Mailgun account for more than one thing, I don't want Duplicacy to use the default (postmaster?) credentials. Click "Manage SMTP credentials", and "Add new SMTP user". I called mine "duplicacy":

Login: duplicacy (textbox) @ long string dot mailgun dot org. Button: Create SMTP Credential

The password isn't shown on screen, instead you copy it to clipboard:

Now go back to Duplicacy, and click "Send email after completion" and set it up like this, pasting in the password:

Duplicacy email notifications dialog. Server

There were a few ports you can use, but only Server: smtp.mailgun.org:587 worked for me. Trying a different port actually hung the Duplicacy Web UI bugreport; the email sending blocked forever while holding a mutex.

Use the same 'From' and Username` field as your SMTP credentials. Put your email in 'To'.

Put {{Status}} into the Subject line which will be replaced with whether the backup succeeded or failed.

I then clicked 'Test'. My first few tests failed, I looked in the duplicacy_web.log file to see why. My test email ended up in Spam, and I clicked 'Not Spam'. Hopefully that will train GMail not to put this in Spam? But to be sure, in the message kebab-menu, select 'Filter messages like this':

GMail kebab menu. Reply / Forward / Filter messages like this

Then "Never send it to Spam":

And you should be getting backup messages! Now, if only Duplicacy would allow you to only send messages on failure, I'd be very happy.

Mark Hansen

Mark Hansen

I'm a Software Engineering Manager working on Google Maps in Sydney, Australia. I write about software {engineering, management, profiling}, data visualisation, and transport.
Sydney, Australia