Email With Rails 3 and Heroku Net::SMTPSyntaxError: 501 Syntax error

。_饼干妹妹 提交于 2019-12-10 02:36:57

问题


As the title says I'm trying to get a simple email working with Heroku and Rails 3. I'm using this Heroku guide: http://devcenter.heroku.com/articles/smtp

Here is my code:

I generated a mailer that looks like this:

class Invite < ActionMailer::Base
  def signup_notification(user)
    recipients "#{user.first_name} <#{user.email}>"
    from       "Test"
    subject    "Please activate your new account"
    sent_on    Time.now
    body       :var => 'testing'
  end
end

I have a view in app/views/invite/signup_notification.rhtml

UPDATE: I see that .rhtml doesn't work with Rails 3 so I just tried .html.erb but I got the same error.

Your account has been created.
Username: 
Password: 
Visit this url to activate your account:

Then in the Heroku console I did this:

user = User.new(:first_name => 'Me', :email => 'me@hotmail.com', :login => 'me', :password => '1234')

and then this:

Invite.deliver_signup_notification(user)

and if get this error:

Net::SMTPSyntaxError: 501 Syntax error
  /user/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:930:in `check_response`
  /user/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:899:in `getok`
  /user/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:828:in `mailfrom`
  /user/ruby1.8.7/lib/ruby/1.8/net/smtp.rb:653:in `sendmail`

Thanks for any ideas.


回答1:


Your from is invalid. Try from 'test@example.com' instead.




回答2:


If you want to show custom string in from then you can use something like

from  "Test <info@domain.com>"

and when you send email title would be Test




回答3:


The Heroku guide is for Rails < 3.0. Use the Rails guide for 3.0.




回答4:


Net::SMTPSyntaxError 501 error is thrown if you have bad sender address. Sender address should be an email address. Any fake email will also do. like: abc@fakemail.com



来源:https://stackoverflow.com/questions/5998758/email-with-rails-3-and-heroku-netsmtpsyntaxerror-501-syntax-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!