Rails - How to use full email addresses without starting Net :: SMTPFatalError?

I am new to rails and use rails-2.3.5 and ruby-1.8.7. Here is my notifier.rb model:

# app/models/notifier.rb
class Notifier < ActionMailer::Base
  default_url_options[:host] = "foo.com"  

  #This method sends an email with token to users who request a new password
  def password_reset_instructions(user)  
    subject       "Password Reset Instructions"  
    from          "Support Team<support@foo.com>"  
    recipients    user.email  
    sent_on       Time.now  
    body          :edit_password_reset_url => 
                   edit_password_reset_url(user.perishable_token)  
  end  
end

When I call this method, I get the following error:

Net::SMTPFatalError in Password resetsController#create
555 5.5.2 Syntax error. 36sm970138yxh.13

I found an article saying that the problem was a bug in ruby-1.8.4, and that the fix is ​​to remove the angle brackets from the: from field. Of course, if I just use " support@foo.com " instead of "Support Team < support@foo.com >" everything works fine.

rails-2.3.5 API ActionMailer Basics, " < mail address > "; actionmailer. - , ?

+5
3

, , , :

  def password_reset_instructions(user)  
    subject       "Password Reset Instructions"  
    from          "Support Team<support@foo.com>"  
+   headers       "return-path" => 'support@foo.com'
    recipients    user.email  
    sent_on       Time.now  
    body          :edit_password_reset_url => 
                   edit_password_reset_url(user.perishable_token)  
  end  

, , 2.3.6 3.x

+3

perform_delivery_smtp ActionMailer:: Base, rails 2.3.4 2.3.5. - - :

class ApplicationMailer < ActionMailer::Base

  def welcome_email(user)
    recipients user.email from "Site Notifications<notifications@example.com>"
    subject "Welcome!"
    sent_on Time.now
    ...
  end

  def perform_delivery_smtp(mail)
    destinations = mail.destinations
    mail.ready_to_send
    sender = mail['return-path'] || mail.from
    smtp = Net::SMTP.new(smtp_settings[:address], smtp_settings[:port])
    smtp.enable_starttls_auto if smtp_settings[:enable_starttls_auto] && smtp.respond_to?(:enable_starttls_auto)
    smtp.start(smtp_settings[:domain], smtp_settings[:user_name], smtp_settings[:password],
               smtp_settings[:authentication]) do |smtp|
      smtp.sendmail(mail.encoded, sender, destinations)
    end
  end

end
0

All Articles