여러 명의 사용자에게 전자 메일을 보내려고합니다. 나는 메일을 보낼 모든 사용자가있는 @users를 보내는 모델을 가지고 있습니다 ... 이제는 User_mailer에서 mail_out 프로세스가 각 사용자에게 보내는 방법을 알아내는 데 어려움을 겪고 있습니다 (set 각 수신자는 user.email). 요약하자면, 매일 아침 User_ail_out 프로세스를 실행하도록 cron 작업을 설정하고 User_mailer 모델로 전달되는 @users 변수의 각 사용자에게 전자 메일을 보내도록 전자 메일로 보내고 싶습니다. 누군가가 이것을하는 방법을 제안 할 수 있습니까? 제가 아래에 쓴 무엇을 사용할 때 현재 다음과 같은 오류가 점점 오전 :여러 사용자에게 메일 보내기
/usr/lib/ruby/gems/1.8/gems/rails-2.3.5/lib/commands/runner.rb:48: /usr/lib/ruby/1.8/net/smtp.rb:680:in `check_response': 501 5.1.3 Bad recipient address syntax (Net::SMTPSyntaxError)
User.rb
class User < ActiveRecord::Base
acts_as_authentic
validates_format_of :email, :with => /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on => :create
validates_presence_of :birthday => "cannot be left blank"
def self.mail_out
weekday = Date.today.strftime('%A').downcase
@users = find(:all, :conditions => {"#{weekday}sub".to_sym => 't'})
UserMailer.deliver_mail_out(@users)
end
end
User_Mailer.rb
class UserMailer < ActionMailer::Base
def mail_out(users)
@recipients = { }
users.each do |user|
@recipients[user.email]
end
from "somewhere.net"
subject "Check it out"
body :user => @recipients
end
def subscribe(user)
recipients user.email
from "somewhere.net"
subject "Welcome!"
body :user => user
end
end
내가 지금이 오류가 있지만 내가 ... 가까워지고 있어요, 감사 : 구문 에러 (/ 홈/tnederlof을
여기 좋은 쪽지 Theres는 /Dropbox/Ruby/daily_trailer/app/models/user_mailer.rb:7 : 구문 오류, 예기치 않은 tASSOC, 예상 '}' –
신경 쓰지 마세요, 고마워! –