Delivery #4

sj26 opened this Issue May 30, 2011 · 10 comments


None yet

5 participants


It would be nice if MailCatcher could on-send captured messages to their intended recipients, or a separately provided recipient.

@sj26 sj26 was assigned May 30, 2011

Really liking mailcatcher so far. Not sure if this is the same issue, but I'm getting "503 MAIL already given" when trying to send to multiple unique recipients on the same connection. Would gladly help to sponsor this feature with a donation.



Thanks for your interest!

It sounds like whatever you're using to send mail is doing some funky things with the protocol. You should only be sending a single "MAIL" command which includes the from address, then you can send as many "RCPT TO" commands as you like to add multiple unique senders. MailCatcher should handle that fine. Maybe check out the SMTP RFC for details.


Thanks so much for the reply. I am using SwiftMailer ( for sending. When I change the smtp connection to use SendGrid ( or another smtp server that I use, everything works out fine.

So I "think" everything should be fine with the protocol but I admit I can't see the exact commands being sent to the mail servers. I'll see if I can turn on some logging to see the exact commands and pass them along.


So SwiftMailer was indeed sending multiple MAIL FROM commands, which seemed to work fine with other smtp servers. The "protocols/smtpserver.rb" file of the EventMachine gem definitely does not allow this though. ( I commented out the 2 lines from the "process_mail_from" function that were checking for this, restarted Mailcatcher and everything worked great. I'm definitely not a ruby programmer but as far as I can tell I didn't break anything else.


Glad you've found a solution.

I don't want to build a workaround into MailCatcher for broken clients, perhaps you can patch SwiftMailer? In the meantime you know how to get it working. :-)


I just ran into this issue myself. See a very simple example using net/smtp in this gist:

Where in the RFC does it state you can't send multiple MAIL commands? I see this in section 3.3

This command tells the SMTP-receiver that a new mail transaction is starting and to reset all its state tables and buffers, including any recipients or mail data.


FWIW, @crucialwebstudio's "fix" to comment out the lines in EM worked for me too. Pretty sure this isn't an issue of a broken client but rather a broken implementation in EM. I'll take it up with them.


@pjb3 you can certainly send multiple MAIL commands, but it should reset the state of the SMTP exchange. The SwiftMailer client was sending multiple MAIL commands for a single message.

Your issue is slightly different—you should indeed be able to send multiple messages sequentially over the same connection. MailCatcher is set up to do so, the problem is in eventmachine. A repeat MAIL command should reset the state instead of the current error-out behaviour. They haven't fixed it in master either. Send a pull request! Should be simple to slice the state array and send a receive_reset, which should have the same semantic value.


There is a pull request that fixes this issue: eventmachine/eventmachine#288

YMMV but commenting out the relevant lines in process_mail_from didn't work for me, but the pull request above worked fine for me.

@sj26 sj26 modified the milestone: v0.6.0, v0.7.0 Jan 29, 2015

We wanted to use mailcatcher to QA all outgoing mail, but still not block regular mail delivery. Here's what we did:

First, create this wrapper script in /var/build/scripts/multimail.rb:


# This script multiplexes both STDIN and ARGV to two mail programs:
# sendmail, and catchmail (for QA).

handlers = [
  '/usr/sbin/sendmail -t -i',

contents = $
handlers.each do |cmd|
  IO.popen(cmd.split + ARGV, 'w') do |f|

Then we use it just like we use the catchmail wrapper (that it in turns wraps):

chmod ugo+x /var/build/scripts/multimail.rb
echo "sendmail_path = /var/build/scripts/multimail.rb" | sudo tee /etc/php5/mods-available/mailcatcher.ini

Very handy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment