Wrong "from" email when using ActionMailer - ruby-on-rails

Rails 2.3.11
I'm trying to send an activation-style email whenever a user registers. The email gets sent successfully, but has the wrong "from" email address. The subject, content, and recipient's email are all fine. Instead of being sent from activation#[domain].net, they come from [login-name]#box570.bluehost.com.
/app/models/franklin.rb:
class Franklin < ActionMailer::Base
def activation(user)
recipients user.email
from "activation#[sub].[domain].net"
subject "[Product] Registration"
body :user => user
end
end
Applicable part of the controller that calls it:
#user = User.create(
:first_name => params[:first_name],
:last_name => params[:last_name],
:email => params[:email],
:password => params[:password],
:password_confirmation => params[:password_confirmation],
:user_class => "User"
)
Franklin.deliver_activation(#user)
/config/environments/development.rb:
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.action_controller.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :sendmail
Thank you!

This looks like a Bluehost-specific problem. You may need to make sure the activation#[sub].[domain].net e-mail address is actually set up as a full email account with Bluehost (this seems to be a common solution).

Related

Ruby on rails action mailer sending mails from previous setting

Hi i have an app in which i am using action mailer to send the mail ,
i am drowned in this really weird issue
the issue is i set up the mail setting in the development and the production environment to send the mails from the gmail domain . that worked perfectly but then i decided to send emails from my domain
which i purchased from the go daddy
this is my code
development.rb
# Raise an error on page load if there are pending migrations.
config.active_record.migration_error = :page_load
config.consider_all_requests_local = false
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
ActionMailer::Base.perform_deliveries = true
# SMTP settings for gmail
config.action_mailer.smtp_settings = {
:address => "smtpout.secureserver.net",
:port => 80,
:domain => "jobzgo.com",
:user_name => 'mydomainemailid',
:password => 'mydomainpasswrd',
:authentication => "plain",
:enable_starttls_auto => true
}
in controller
def create
#form = Form.create(form_params)
if #form.save
FormMailer.registration_mail(#form).deliver
redirect_to forms_path
end
end
i dont know how but i am still receiving the mails from gmail domain and the old gmail id i provided as the sender
Can anyone please tell me why this is happening along with the solution
wud be really a great help stuck in this issue
You have set the default from: to your Gmail address in your app/mailers/application_mailer.rb.
BTW I would highly recommend you to move credentials out of the codebase into the environment variables.

No email alerts in mailcatcher, but able to send emails to valid account?

I am running a Rails app and using Mailcather gem as an SMTP service. It was said that it can catch all outgoing emails, however I've done making correct settings in config/environments/development.rb, testing it to send email, but no email catched in either 127.0.0.1:1080 and localhost:1080. But the email was sent and received tho. I've tried all of the possible configurations. Here is my config/development.rb
config/development.rb
Ror::Application.configure do
# Mailer
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => '127.0.0.1:3000' }
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = { :address => "127.0.0.1", :port => 1025 }
end
Here is my user_mailer.rb
class UserMailer < ActionMailer::Base
default :from => "aaaaaaaaa#gmail.com"
def registration_confirmation(user)
#user = user
mail(:to => user.email, :subject => "Registered")
end
end
I used the registration_confirmation() method to check whether user is registered or not via email. But none of of the email popped up in mailcatcher. I did install it under rvm. I did test install it both with wrapper and without wrapper but the result still the same. Bottom line is, it is able to send emails outside, but can't receive email inside. Or any notifications. Did I miss something? Any advice or corrections would be appreciated. Thanks
You call the mail method like this:
UserMailer.registration_confirmation(user).deliver

Rails Mailer: change file when delivery_method :file

I want to have the file named Timestamp + normal_mail_name + ".eml"..
I looked into the rails source code, the mail-gem source code and the letter opener-gem.. Could you give me a hint how to (monkey-patch) the rails mailer to support that i can specify something like:
config.action_mailer.file_settings = { :location => Rails.root.join('tmp', 'mail'), :file_name => Time.now.to_i.to_s + "mail.eml" }
Thank you!
UPDATE:
It would be also nice to have this mails automatically opened with my local associated email programm with launchy, like the letter opener gem.. i would do it myself, but i dont understand the sourcecodes..
I think you have a lot of mailer stuff and you´ll want to debug the mail body, texts, etc.? Am I right?
If I am right, I would not send the mails with delivery_method :file, I just would create a real email (for example gmail) account and send the mails over a test account.
For example in your config/environments/development.rb:
email_settings = YAML::load(File.open("#{Rails.root.to_s}/config/mail.yml"))[Rails.env] rescue nil
if email_settings.nil?
config.action_mailer.raise_delivery_errors = false
config.action_mailer.perform_deliveries = false
config.action_mailer.delivery_method = :file
else
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "#{email_settings["address"]}",
:port => email_settings["port"],
:authentication => "#{email_settings["authentication"]}",
:user_name => "#{email_settings["user_name"]}",
:password => "#{email_settings["password"]}",
:enable_starttls_auto => email_settings["enable_starttls_auto"]
}
end
And your mail.yml file:
development:
address: smtp.gmail.com
port: 587
authentication: login
user_name: test#your-domain.com
password: yourpassword
enable_starttls_auto: true
This is not really a direct answer for your question, but maybe this work around is a good choice for you. You could also configure your other environments the same way, dependent on your needs.
If you just want skip the transmission of the emails through a real mail server to view your emails locally, two good solutions I've used are:
https://github.com/ryanb/letter_opener
https://github.com/37signals/mail_view
A non-free, OSX-specific solution is to use http://mocksmtpapp.com/
If you want to have a copy of the raw email (headers and all), one way I would do it would be write an email interceptor and write the contents of the mail object to disk.
http://railscasts.com/episodes/206-action-mailer-in-rails-3
Something like this for lib/development_mail_interceptor:
class DevelopmentMailInterceptor
def self.delivering_email(message)
message.perform_deliveries = false
File.open("#{Time.now.to_i}-email.eml", "w") { |f| f.write(message.to_s) }
end
end
and in config/initializers/setup_mail.rb
Mail.register_interceptor(DevelopmentMailInterceptor) if Rails.env.development?

Rails 3.0, ActionMailer delivery not working, no error message displayed

I'd like to play around with sending mail from Rails in a development environment. My message is getting rendered (I can see it in the terminal I'm running rails console in).
In config/development.rb I have (yes, the port is really 26):
config.action_mailer.delivery_method = :smtp
config.action_mailer.perform_deliveries = true
config.action_mailer.raise_delivery_errors = true
ActionMailer::Base.smtp_settings = {
:address => "mail.mydomain.com",
:port => 26,
:user_name => "me#mydomain.com",
:password => "removed",
:authentication => :login
}
I have in mailers/user_mailer:
class UserMailer < ActionMailer::Base
default from: "me#mydomain.com"
def send_an_email
mail(:to => "me#gmail.com", :subject => "Test from Rails")
end
end
I have a view that's getting rendered properly in views/user_mailer/send_an_email.text.erb. I'm calling UserMailer.send_an_email.deliver upon a page request.
Rails doesn't complain about my configuration. I see the message in the rails server console output. However, I never get an e-mail, and I don't see any error messages in the console output (as you can see above, raise_delivery_errors = true!.
Steve, by chance have you made sure you're calling the deliver method?
mail(:to => "me#gmail.com", :subject => "Test from Rails").deliver
I forgot to do that, and was quite confused by the lack of errors. :)

Actionmailer not delivering mail, with rails 3

I am trying to make an application, that sends an email when user registers.
i put in the smtp settings for gmail in the config/application.rb file and the mail function looks like
mail(:to => "me#me.com", :subject => "Mail!", :from => "another#me.com", :content_type => "text/html")
now when i see the logs, i see that it says mail has been sent, but i never receive any mail at all...
also, when i call the mail deliver function, Emails.signed(#user).deliver, the form page does not redirect, but it works if i comment out the email sending code that is either
Emails.signed(#user).deliver
or
mail(:to => "me#me.com", :subject => "Mail!", :from => "another#me.com", :content_type => "text/html")
Thanks :)
Edit: development.rb
App::Application.configure do
# Settings specified here will take precedence over those in config/environment.rb
# In the development environment your application's code is reloaded on
# every request. This slows down response time but is perfect for development
# since you don't have to restart the webserver when you make code changes.
config.cache_classes = false
# Log error messages when you accidentally call methods on nil.
config.whiny_nils = true
# Show full error reports and disable caching
config.consider_all_requests_local = true
config.action_view.debug_rjs = true
config.action_controller.perform_caching = false
# Don't care if the mailer can't send
config.action_mailer.raise_delivery_errors = true
config.action_mailer.perform_deliveries = true
# Print deprecation notices to the Rails logger
config.active_support.deprecation = :log
end
Somewhat late, but nevertheless maybe this will save someone a few hours of head banging. This is probably only relevant to sending emails from gmail.
First, in order to help debugging the situation, set the following line in development.rb to true (assuming you're in development mode):
config.action_mailer.raise_delivery_errors = true
This will make ActionMailer not to silently ignore errors.
When I did that, I realized gmail is refusing my username and password.
I then went to my configuration file where I put all the Action Mailer config directives (for me it was in development.rb, there is probably a better place to put it), and noticed that :user_name was set to "admin" rather than "admin#thedomain.com". Changing it solved the problem. Here is my corrected part of development.rb:
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => 587,
:domain => 'thedomain.com',
:user_name => 'admin#thedomain.com',
:password => '<password>',
:authentication => 'plain',
:enable_starttls_auto => true }
References:
http://forums.pragprog.com/forums/43/topics/541
http://edgeguides.rubyonrails.org/action_mailer_basics.html
Another thing not to forget: you have to restart the application after making changes in your environment config files. when using passenger this can quickly be missed :)
that's what solved my "problem" when ActionMailer didnt want to send emails without showing any errors..
The things written here did not help me.
I am using Rails 3.2.8 and I spent several hours trying to figure this out and it was very simple in the end. I forgot to call .deliver() on the Mail::Message object that is returned by mail(:to => #user.email, :subject => 'Welcome to the Site') method call.
Just leave everything like it is specified in official RoR tutorial.
That is, in your development/production environment files, make a section like:
# mailer
config.action_mailer.raise_delivery_errors = true
config.action_mailer.delivery_method = :smtp
config.action_mailer.smtp_settings = {
address: 'smtp.gmail.com',
port: 587,
domain: 'gmail.com',
user_name: '<username>#gmail.com',
password: '<password>',
authentication: 'plain',
enable_starttls_auto: true
}
And then you subclass ActionMailer::Base, for example like this:
class InfoMailer < ActionMailer::Base
default from: "<username>#gmail.com"
def welcome_user_and_send_password(user, password)
default_url_options = self.default_url_options()
#user = user
#password = password
#url = default_url_options[:host]
mail(:to => #user.email, :subject => 'Welcome to the Site').deliver()
end
end
After that, you can simply use this InfoMailer method from your code like a class method:
InfoMailer.welcome_user_and_send_password(user, password)
If you're using the test environment, be sure to comment out this line of code in environments/test.rb:
config.action_mailer.delivery_method = :test

Resources