I’m having trouble with MailGun’s batch email feature through SMTP. Even though I set up recipient variables correctly, all email addresses still show up in the To field for every person who gets the message.
The variables themselves work fine and get replaced properly in the email content. But according to MailGun docs, when you use recipient variables, each person should only see their own email in the To field.
This happens because MailGun’s SMTP batch processing needs a specific Content-Type header that most people miss. You need to include Content-Type: text/html; charset=utf-8 and X-Mailgun-Tag: batch in your headers when sending with recipient variables. Without these, MailGun treats it like a regular multi-recipient email instead of using the batch engine that separates recipient variables. I spent hours debugging this exact issue - variables worked fine but recipients could see each other’s addresses. The docs don’t make this clear enough. Also check that your SMTP client isn’t overriding these headers since some email libraries strip custom headers by default.
Check your Mailgun domain settings. I had the exact same issue - batch mode wasn’t enabled for SMTP on my domain. Go to the domain configuration tab and toggle it on. Without it, Mailgun handles your emails like regular multi-recipient sends instead of proper batching.
Honestly, MailGun’s SMTP for batch emails is a nightmare I’ve dealt with way too many times. Your code’s probably fine - it’s MailGun’s SMTP that’s unreliable.
I used to waste hours messing with headers and domain settings. Here’s what actually works: ditch SMTP completely.
I built an automation that hits MailGun’s API directly instead. It pulls your email list, handles recipient variables properly, and sends personalized emails without the To field disasters.
Best part? Upload your contacts and template once. The automation handles API calls, manages batching limits, and deals with errors automatically. No more debugging SMTP headers or wondering why everyone can see each other’s addresses.
I’ve been running this for our customer emails for months - rock solid. Each person gets a clean email with just their address in the To field.
I’ve dealt with this exact issue before and it drove me crazy for weeks. MailGun’s SMTP batch sending is honestly pretty finicky with the recipient variables.
When you put multiple emails in the To header like that, MailGun’s SMTP interface doesn’t always honor the recipient variables properly. It works better through their API, but if you’re stuck with SMTP, you need to send individual emails instead of trying to batch them.
I ended up automating the whole email process differently. Instead of fighting with MailGun’s quirky SMTP behavior, I built a workflow that handles all the recipient management and personalization automatically.
The workflow takes your email list, processes each recipient individually, and sends personalized emails without any of the header mess you’re dealing with. It handles all the variable substitution and makes sure each person only sees their own email address.
I set this up once and now I never have to worry about recipient variables or SMTP headers again. The automation just takes care of everything and sends clean, personalized emails every time.
Your setup looks right technically, but there’s a gotcha with MailGun’s SMTP that trips up tons of developers. The recipient variables feature through SMTP needs special handling that’s different from their API docs. I’ve seen MailGun’s SMTP server process the To header before applying recipient variable logic, so all addresses stay visible. This usually happens when the SMTP connection doesn’t properly authenticate batch sending on their end. Try adding the X-Mailgun-Variables header with your recipient variables - it forces proper processing. Also check that your SMTP credentials have batch sending permissions in your MailGun dashboard. Another culprit could be timing. If you’re sending emails too fast, MailGun might not process recipient variables correctly. A small delay between SMTP submissions often fixes this. The annoying part? Variable substitution works fine while the To field stays broken, making debugging confusing since everything else seems to work.
This happens because of how MailGun handles SMTP envelope vs message headers. Your SMTP client library probably doesn’t support MailGun’s batch mode properly - most standard libraries weren’t built for MailGun’s setup. I ran into this exact problem when switching from SendGrid. Changing SMTP libraries fixed it right away. Libraries like nodemailer need explicit config to work with MailGun’s batch features. Also check you’re hitting the right SMTP endpoint - MailGun has different servers per region and they don’t all handle recipient variables the same way. Your auth method matters too since basic auth vs API key auth affects how their backend processes recipient variables.