I’m running into a problem when trying to send emails to Gmail addresses that contain plus signs for filtering. When I attempt to deliver an email to something like [email protected], I get this error:
(Net::SMTPSyntaxError) "501 5.1.3 Bad recipient address syntax"
This seems to be happening in the net/smtp library. The plus sign feature is a standard Gmail functionality, so I’m wondering if the validation is being too restrictive.
Has anyone encountered this issue before? Is there a workaround or fix available for the net/smtp module to handle these types of email addresses properly?
The error occurs during the SMTP delivery process and prevents emails from being sent to any address containing the plus character, even though these are valid email addresses according to RFC standards.
weird, i’ve sent emails to gmail+ addresses before without issues. what ruby version are you using? might be worth checking if you’re escaping the email address somewhere in your code before passing it to smtp. also try updating your gems if possible
This looks like a character encoding issue with your SMTP setup. I’ve hit this before with corporate email servers that are picky about address parsing. Try wrapping your recipient email in quotes when you pass it to the SMTP method - like “[email protected]” instead of the bare address. The net/smtp library sometimes chokes on special characters in unquoted addresses even though they’re totally valid. Also check if you’re using any email validation gems that might be rejecting the address before it hits the SMTP layer. I’ve seen validator gems that don’t handle plus addressing properly despite it being standard.
Had this exact problem about a year ago with email notifications in Rails. The issue was URL encoding in recipient address validation - the plus sign got encoded as %2B before hitting the SMTP library. For me, the fix was checking email sanitization. ActionMailer was preprocessing addresses and mangling the plus signs. Log the actual string passed to the SMTP method right before delivery to see if it’s still in original format. Also verify your SMTP config settings. Some mail servers are stricter with validation even though plus addressing is RFC compliant. I switched from default net/smtp settings to explicitly setting mail server parameters and that fixed the syntax error.