I am sending email using action mailer in my rails app. But it allows only one default sender. This is my UserMailer class:
class UserMailer < ActionMailer::Base
default :from => "[email protected]"
def welcome_email(user, order)
@user = user
@order = order
mail(:to => user.email, :subject => "Your Order")
end
def signup_email(user)
@user = user
mail(:to => user.email, :subject => "Thank you.")
end
def invite_confirm(curuser,usemail,post)
@greeting = "Hi"
@user = curuser
@post = post
mail(:to => user.email, :subject => "Hello")
end
end
I tried this:
class UserMailer < ActionMailer::Base
def welcome_email(user, order)
@user = user
@order = order
mail(:to => user.email, :subject => "Your Order", :from => "[email protected]")
end
def signup_email(user)
@user = user
mail(:to => user.email, :subject => "Thank you.", :from => "[email protected]")
end
def invite_confirm(curuser,usemail,post)
@greeting = "Hi"
@user = curuser
@post = post
mail(:to => user.email, :subject => "Hello", :from => "[email protected]")
end
end
But still it is sending email from "[email protected]"
Is there any way to change sender for each method written in UserMailer class? Am i supposed to change anywhere else?
In config/environments/development.rb and config/environments/production.rb i have this:
config.action_mailer.smtp_settings = {
:address => "smtp.gmail.com",
:port => "587",
:domain => "gmail.com",
:authentication => "plain",
:user_name => "[email protected]",
:password => "example",
:enable_starttls_auto => true
}
I guess, i should not change anything here.
You can pass it as a parameter to the mail
method:
def new_mail
mail from: "[email protected]", to: "[email protected]"
end
I think you want to send mail with three different emails of the for-each action. Because you use gmail, you need Sending mail from a different address.
No single vendor is optimal for all three types of email; you likely will use several vendors.
For “company email,” that is, sending individual email to customers or business associates, you’ll probably use Gmail or Google Apps for Business. For a single address, you can set up a single Gmail account to receive and send email from a different address. More likely, you’ll want several email addresses for your company mail. For that, use Google Apps for Business.
Send Email with Rails
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With