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?
Related
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.
I want to display the movies associated to a given author. On the author's page, I want users to be able to paginate, sort, and filter by keyword.
Everything works fine on my local machine. But, in production, the list of movies on the author's page is empty, and I can't figure out why. In production, in the console, I tested the following expressions, but no luck (always returns 0, while it returns values > 0 in dev):
ruby-1.9.2-p290 :042 > Movie.search(:with => {:author_ids => [6]}).count
=> 0
ruby-1.9.2-p290 :043 > Movie.search(:with => {:author_ids => 6}).count
=> 0
The weird thing is that I'm using a very similar code to display the movies associated to a topic on a topic's page, and it works great in development AND in production. For instance:
ruby-1.9.2-p290 :051 > Movie.search(:with => {:topic_ids => 2}, :per_page => 1000).count
=> 295
Here is how I define my Movie class:
class Movie < ActiveRecord::Base
belongs_to :author
has_many :topics
...
define_index('movie') do
...
has author(:id), :as => :author_ids,
:facet => true
has topics(:id), :as => :topic_ids,
:facet => true
...
end
...
end
And here is what my Author show controller looks like:
def show
#author = Author.find(params[:id])
keywords = params[:what] || ""
with_params[:author_ids] = [#author.id]
#movies = Movie.search(
keywords,
:with => with_params
)
end
This leads me to believe there is something wrong with the Sphinx index in production, but I'm not sure how to investigate further to find the root of the problem...
UPDATE: Following Pat's suggestion, I updated Sphinx and everything was solved (I upgraded from 0.9.8 to 0.9.10)! I was confused because Sphinx is NOT a Gem (even though a Sphinx gem exists)... So I had to go through the regular download, make, make install process.
I'll start with the obvious, but maybe this has already been tried - is the author_ids attribute something relatively new? Have you rebuilt (indexed and restarted) Sphinx since adding that attribute? rake ts:rebuild is the easy way to do that.
Update: It turns out updating Sphinx was the fix here - Alex can confirm which version, but I'm guessing 0.9.9 or better should do the trick.
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.
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
So I'm getting a 'No route matches' error, and being new to Rails 3 (and Rails in general), I really don't know what the problem is. Here are the pertinent routes:
resources :users
#...
match 'reset_password(/:reset_password_code)' => 'users#reset_password', :as => :reset_password, :via => :get
match 'reset_password' => 'users#reset_password_submit', :as => :reset_password, :via => :post
The GET method works fine. I get a routing error when the form POSTs that's generated on the get page, which starts like this.
<%= form_for #user, :url => reset_password_url do |f| %>
It looks like it's posting to the right spot, as the url is generated using 'reset_password_url', it's posting to it, and the url looks as it should... anyone have any ideas?
UPDATE
I'm using Rails 3.0.4
I've tried taking out every other route except for the ones that I've mentioned here, and I still can't figure out why it's not working.
Figured it out!
In my form, rails was (correctly) assuming that since I had a user that I was using with the form_for helper, that I wanted to update the user, not make a new one.
Therefore, it was using the PUT method to post my form. To solve the routing problem, I just had to change the last route to:
match 'reset_password' => 'users#reset_password_submit', :as => :reset_password, :via => :put
I only found the issue after using the Web Inspector in webkit to see the whole request, and looked at the _method parameter being sent in.