Skip to content

Net::SMTPSyntaxError with invalid email address that passed validation

Problem

Error: "Net::SMTPSyntaxError: 501 Invalid command or cannot parse to address" when a user issued a PUT request to /profile/emails/:email_id/resend_confirmation_instructions. See the Sentry report.

Backtrace

Net::SMTPSyntaxError: 501 Invalid command or cannot parse to address

  net/smtp.rb:969:in `check_response'
    raise res.exception_class, res.message
  net/smtp.rb:937:in `getok'
    check_response res
  net/smtp.rb:865:in `rcptto'
    getok("RCPT TO:<#{to_addr}>")
  net/smtp.rb:846:in `block in rcptto_list'
    rcptto addr
  net/smtp.rb:844:in `each'
    to_addrs.flatten.each do |addr|
...
(161 additional frame(s) were not displayed)

Net::SMTPSyntaxError: 501 Invalid command or cannot parse to address

Proposal

Validate Email#email with the valid_email gem (instead of DeviseEmailValidator).

Out of scope

Validating other email attributes with the valid_email gem (instead of DeviseEmailValidator) is out of scope. If tightening validation on Email#email is successful, then DeviseEmailValidator can be replaced in a follow-on issue.

Technical notes

Use of Devise.email_regexp for validating emails was introduced in gitlab-foss!2771 (merged)

Edited by Dan Jensen