Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 Net::SMTPSyntaxError: 501 Syntax error for bulk email

I have a cronjob that sends newsletters everyday. For some reason, there was an error today.

I checked the stack trace and got this

Net::SMTPSyntaxError: 501 Syntax error

    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:957:in `check_response'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:926:in `getok'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:869:in `rcptto'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:850:in `block in rcptto_list'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:848:in `each'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:848:in `rcptto_list'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:663:in `send_message'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:113:in `block in deliver!'
    from /usr/local/rvm/rubies/ruby-2.1.5/lib/ruby/2.1.0/net/smtp.rb:521:in `start'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/network/delivery_methods/smtp.rb:112:in `deliver!'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/message.rb:2141:in `do_delivery'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/mail-2.6.3/lib/mail/message.rb:236:in `block in deliver'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/actionmailer-4.1.8/lib/action_mailer/base.rb:527:in `block in deliver_mail'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/notifications.rb:159:in `block in instrument'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/notifications/instrumenter.rb:20:in `instrument'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/activesupport-4.1.8/lib/active_support/notifications.rb:159:in `instrument'
... 3 levels...
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/commands/console.rb:90:in `start'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/commands/console.rb:9:in `start'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:69:in `console'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/commands/commands_tasks.rb:40:in `run_command!'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/commands.rb:17:in `<top (required)>'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/app_rails_loader.rb:43:in `require'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/app_rails_loader.rb:43:in `block in exec_app_rails'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/app_rails_loader.rb:32:in `loop'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/app_rails_loader.rb:32:in `exec_app_rails'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/lib/rails/cli.rb:5:in `<top (required)>'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/bin/rails:9:in `require'
    from /var/www/lsd-core/shared/bundle/ruby/2.1.0/gems/railties-4.1.8/bin/rails:9:in `<top (required)>'
    from /usr/local/rvm/gems/ruby-2.1.5/bin/rails:23:in `load'
    from /usr/local/rvm/gems/ruby-2.1.5/bin/rails:23:in `<main>'
    from /usr/local/rvm/gems/ruby-2.1.5/bin/ruby_executable_hooks:15:in `eval'

Initially I thought it was a bad email format in the recipients list, but after weeding a few out, I would still get the error after manually running the newsletter mailer.

I tried looping through each recipient and send them each the email, and it worked! Even for the bad emails.

Is there a maximum number of recipients when sending with ActionMailer?

like image 334
nzdrml Avatar asked Jun 25 '15 06:06

nzdrml


1 Answers

As far as I know, ActionMailer imposes no limit on the number of recipients. The error you are getting originates from your SMTP server, so that's most likely where the fault lies.

The error was returned when sending one of several RCPT TO: commands at net/smtp.rb:869. The most likely explanation would be a malformed address, but you state that each address worked when sent to on their own. You could try sending the email to a large number of your own addresses and see if the same error appears.

Regardless of whether you find the cause, you might want to consider sending each newsletter separately. The added overhead of sending one mail per recipient is likely to be worth it if it avoids glitches like this. Good luck!

like image 136
lime Avatar answered Oct 25 '22 09:10

lime