Note that there are some explanatory texts on larger screens.

plurals
  1. POMailing Multiple Users Syntax
    primarykey
    data
    text
    <p>I am trying to send an email to multiple users. I have a model that sends @users, which has all of the users I am going to be mailing... now when in the User_mailer I am having trouble figuring out how to tell the mail_out process to send to each of the users (set each recipient the user.email). To summarize, I want to set a cron job to run the User.mail_out process each morning, have it email each user in the @users variable being passed to the User_mailer model. Can someone please suggest a way of doing this? I am currently getting the following error when using what I have written below:</p> <pre><code>/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) </code></pre> <p>User.rb</p> <pre><code>class User &lt; ActiveRecord::Base acts_as_authentic validates_format_of :email, :with =&gt; /\A([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\Z/i, :on =&gt; :create validates_presence_of :birthday =&gt; "cannot be left blank" def self.mail_out weekday = Date.today.strftime('%A').downcase @users = find(:all, :conditions =&gt; {"#{weekday}sub".to_sym =&gt; 't'}) UserMailer.deliver_mail_out(@users) end end </code></pre> <p>User_Mailer.rb</p> <pre><code>class UserMailer &lt; ActionMailer::Base def mail_out(users) @recipients = { } users.each do |user| @recipients[user.email] end from "somewhere.net" subject "Check it out" body :user =&gt; @recipients end def subscribe(user) recipients user.email from "somewhere.net" subject "Welcome!" body :user =&gt; user end end </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload