Ruby Net::SMTP fails with plus sign in email addresses

I’m having trouble sending emails to addresses that contain a plus sign, like [email protected]. When I try to send mail to these addresses, I get this error:

(Net::SMTPSyntaxError) "501 5.1.3 Bad recipient address syntax"

The error comes from Ruby’s built-in SMTP library. It seems like the validation is too strict and doesn’t allow plus signs in email addresses, even though they’re perfectly valid according to email standards.

Here’s the stack trace I’m getting:

/usr/local/lib/ruby/1.8/net/smtp.rb:679:in `validate_response'
/usr/local/lib/ruby/1.8/net/smtp.rb:652:in `get_response'
/usr/local/lib/ruby/1.8/net/smtp.rb:634:in `recipient_to'
/usr/local/lib/ruby/1.8/net/smtp.rb:545:in `transmit_message'
/usr/local/lib/ruby/1.8/net/smtp.rb:471:in `send_message'
/usr/local/lib/ruby/gems/1.8/gems/actionmailer-2.3.5/lib/action_mailer/base.rb:684:in `smtp_delivery'

Has anyone encountered this issue before? Is there a workaround or fix for the net/smtp library?

Just hit this same issue. It’s not just server validation - Ruby 1.8’s Net::SMTP has wonky address parsing that throws validation errors before it even talks to your SMTP server. Try wrapping the email in angle brackets when you call send_message: <[email protected]> instead of [email protected]. Forces the library to treat it like proper RFC 2822 format. Also check if you’re double-encoding the address somewhere in your pipeline. Your stack trace shows it’s dying on the RCPT TO command, so the address is getting mangled before it sends.

that’s weird - i’ve sent emails with + signs too! which smtp server are u using? some act weird with validation. maybe look into ur smtp provider’s known issues with plus addressing instead of putting the blame on ruby.

Had the same issue with Ruby 1.8. The problem isn’t Net::SMTP’s validation - it’s your SMTP server rejecting the recipient addresses. That 501 5.1.3 error is server-side, not Ruby. I switched to an SMTP provider that actually supports RFC 5233 plus addressing. Gmail’s SMTP handles plus signs fine, so does SendGrid. If you can’t switch providers, try URL encoding the plus sign as %2B before passing it to the SMTP methods. Some servers accept this even when they reject the raw plus sign.