Rails 3: Actionmailer :BCC field doesn't work - ruby-on-rails-3

The :bcc field doesn't seem to work.
mail(:to => "xx#xxx.org",
:bcc => "xx1#xxx.org",
:subject => "Welcome to My Awesome Site")
I want to pass to the :BCC field an array of 100 e-mails to send but this doesn't work even when I pass only 1 value.
Thanks

I just ran into this as well. However, I narrowed it down to my use of SES for delivery. I found this issue
https://github.com/drewblas/aws-ses/issues/16
When I used sendmail, the bcc worked just fine.

Related

Ruby on rails validates with code not working

Is there a mistake here? I want the entry to start with http://amzn.com/w/ followed by anything. But what ever I enter I get the error message.
validates :wl_url, format: { with: /\A(http:\/\/amzn\.com\/w\/)+([a-z0-9]*)\z/,
message: 'Please make sure the Wish List code starts with http://amzn.com/w/, if unsure see "how it works" page for instructions.'}
Try this syntax:
validates_format_of :wl_url, :with => /\A(http:\/\/amzn\.com\/w\/)+([a-z0-9]*)\z/i, :message => "Please make sure the Wish List code starts with http://amzn.com/w/, if unsure see "how it works" page for instructions."

Rails send individual email to each user?

I'm sending around 100 emails at a time using the following mailer in my Rails 3 application:
def new_resource_notification(resource, user)
#resource = resource
#user = user
mails = User.where(:email_subscribe => true).map(&:email)
mail(:to => "admin#domain.com", :bcc => mails, :subject => "New item added")
end
When I look at the outgoing email logs it's sending each email to admin#domain.com and adding all users to the bcc field as expected.
What I would prefer, if possible, is for each email to be sent to the users email without any bcc entries.
Is this possible and/or recommended?
Yes, it is possible, but you will have to do a loop, which will send single e-mail to each user. It will take much more rescources and will be slower; that's why lots of mailers do "BCC method" rather than send single emails.

Actionmailer BCC not working

Does BCC not work in Rails 3? My TO and cc work great but BCC just will not work. I saw other people were having similar problems so I was wondering if anyone solved it. I am using
actionmailer (3.2.6). Here is the code I have:
mail(:to => email_to, :from => email_from, :bcc => ["example#gmail.com"], :subject => #subject)
http://api.rubyonrails.org/classes/ActionMailer/Base.html
You are doing it correctly. Are you sure you are not using the same address in your BCC as your TO?

RAILS3: Set query parameters to post in functional tests?

I have a Rails3 app that has Workflows, and they have many WorkAssignments. WorkAssignments have a field, work_sent_date, the date work was sent to the person. On the Workflow edit screen I display a work sent date field, but Workflow does not have an attribute work_sent_date. If any work assignments have a date, I display the most recent one and it can't be edited. If all are blank, I display a text box that is editable and in WorkflowController#update, if that date is filled it, the work assignments' work_sent_date field get that date.
It works when I test it manually. I suppose I could just create an attribute for it, but I'm trying to be slick and not have redundant data.
I'm trying to write a test for this. First I assert that the WorkAssignment#work_sent_date is blank for all work assignments. Then I try a "post :update" and I can't figure out how to pass in the work_sent_date value, which is a form field but not an attribute. What I want to do is something like.
test "setting work_sent_date in wf sets it in wa" do
#workflow.work_assignments.each do |wa|
assert wa.work_sent_date.blank?
end
get :edit, :id => #workflow.id
assert_response :success
post :update, :workflow => #workflow.attributes, :parameters => {'work_sent_date' => Date.today.to_s}
#workflow.work_assignments.each do |wa|
assert_equal(wa.work_sent_date, Date.today)
end
end
But that parameters field doesn't work. There's no error, but I keep getting failures because wa.work_sent_date is still nil, so it's not getting passed in correctly. How do I pass today's date in as an extra parameter?
(Or maybe there's a better way to do the whole thing, which I would gladly consider.)
I know this is complicated. I hope I explained it well. Any suggestions would be appreciated. I've googled to death and can't find anything.
Found my problem. Syntax way wrong. Here's what it should be. This works.
put :update, :id => #workflow.id, :workflow => #workflow.attributes, :work_sent_date => Date.today.to_s
You can also refactor out the create and edit as follows:
protected
def edit_workflow(workflow, options = {})
post :update, :id => workflow.id, :workflow => workflow.attributes.merge(options)
end
def create_workflow(options = {})
post :create, :workflow => {}.merge(options)
end
end

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

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.
Your from is invalid. Try from 'test#example.com' instead.
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
The Heroku guide is for Rails < 3.0. Use the Rails guide for 3.0.
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