Reputation: 1365
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.
Upvotes: 8
Views: 7982
Reputation: 141
Here's what i use, it allows to make a "title" different.
class UserMailer < ActionMailer::Base
default :from => '"example" <[email protected]>'
def send_signup_email(user)
@user = user
mail(to: @user.email, subject: 'example')
end
end
Upvotes: -1
Reputation: 1365
I found that, this can't be done using smtp. Need to use amazon SES which allows multi sender support.
Upvotes: 2
Reputation: 8220
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.
Upvotes: 1
Reputation: 38543
You can pass it as a parameter to the mail
method:
def new_mail
mail from: "[email protected]", to: "[email protected]"
end
Upvotes: 10