The best open source alternative to Mailgun is Mailwhale, which is both free and Open Source. If that doesn't suit you, our users have ranked more than 50 alternatives to Mailgun and four of them is open source so hopefully you can find a suitable replacement. Other interesting open source alternatives to Mailgun are Cuttlefish.io (Free, Open Source), Postal (Free, Open Source) and iReach (Free, Open Source).
The open source mail server - Postal is a complete and fully featured mail server for use by websites & web servers. Think Sendgrid, Mailgun or Postmark but open source and ready for you to run on your own servers.
iReach is an open source web-based application developed by Lone Star Technologies which will allow you to create and manage html email campaigns. Some uses include newsletters, advertising campaigns, product notifications, and press releases.