I have a problem with choosing specific email template. I have the following mailer:
class NewsletterMailer < ActionMailer::Base
def confirmation_email(subscriber)
#subscriber = subscriber
mail(to: #subscriber.email,
subject: t('.confirmation_subject'))
end
end
And two emails templates that are stored in app/views/newsletter_mailer:
confirmation_email.html.erb
confirmation_email.en.html.erb
Is there any way to set in this mailer action to use this: "confirmation_email.en.html.erb"?
Thanks in advance for any help.
Try this:
mail(to: #subscriber.email,
template_name: 'confirmation_email.en.html.erb',
subject: t('.confirmation_subject'))
You may read more at Mailer Views
Related
I am trying to send bulk emails to a bunch of receivers. The email is being delivered to the expected receivers but it is CCing all the receivers. I dont't want receivers to be able to see other receivers emails. I might be doing it wrong. Below is my ruby method in ApplicationMailer.
class WantedEquipmentMailer < ApplicationMailer
def sendmail
#receiver = WantedEquipment.where(sub_category_id: "#{a}", status: 2).pluck(:email)
mail(to: #receiver, subject: #subject)
end
end
Equipment.rb
def email_newequip_matches_wanted
WantedEquipmentMailer.sendmail.deliver
end
What changes should I make so that it wont cc all the receivers stored in that array (#receiver). ?
You can refer to something like this which i just pulled from the docs. Action Mailer classes
class NotifierMailer < ApplicationMailer
default from: 'no-reply#example.com',
return_path: 'system#example.com'
def welcome(recipient)
#account = recipient
mail(to: recipient.email_address_with_name,
bcc: ["bcc#example.com", "Order Watcher <watcher#example.com>"])
end
end
Send across the mails with :bcc the way it is done in basic mail clients.
I've created a basic mailer and am not able to see the preview using the following path: http://localhost:3000/rails/mailers/calendar_mailer/calendar_email
Here is my mailer, preview, and email body code:
calendar_mailer.rb:
class CalendarMailer < ActionMailer::Base
default from: "notifications#cogsmart.com"
def calendar_email(user)
#user = user
mail(to: #user.email, subject: 'Your Cogsmart To Do List')
end
end
calendar_mailer_preview.rb:
class CalendarMailerPreview < ActionMailer::Preview
def calendar_email
CalendarMailer.calendar_email(User.first)
end
end
calendar_email.html.erb:
<h1>Thanks #user.name for using Cogsmart, here's your calendar</h1>
As described here
The preview needs to go in the test/mailers/previews folder
I will preface this saying that I know almost nothing about rails. But I am trying to fix this issue involving rails so any help would be greatly appreciated (and also, if you could dumb it down for me that would be great!)
We have a rails email notification set up for two of our sites. If a user fills out an application on our English site, then a notification email is sent to person A. If a user fills out an application on our French site, then a notification email is sent to person B.
However, at the moment it seems like all emails are going to person A regardless of whether an application is filled out on the English or French site. How can I fix this?
Here is the code from the admin_mailer.rb file:
class AdminMailer < ActionMailer::Base
default from: 'noreply#canwise.com'
def contact_email
#contact = Contact.last
mail to: 'email1#1test.com'
end
def application_email
#application = Application.last
mail to: 'email1#test.com'
end
def eps_contact_email
#contact = Contact.last
mail to: "email2#test.com"
end
def eps_application_email
#application = Application.last
mail to: 'email2#test.com'
end
def salesforce_application_failure(application)
subject = "Application #{application.id} submitted by #{application.firstName} #{application.lastName} failed to submit to salesforce."
mail(to: 'test#test.com', subject: subject) do |format|
format.text { render text: '' }
end
end
end
And here is the code from the application.rb file:
def email_notification
if provider == 'www.frenchsite.com'
AdminMailer.eps_application_email.deliver
else
AdminMailer.application_email.deliver
end
end
HELP PLEASE!
If the emails are all going to email1#test.com, then it only means that your provider for french is not matching 'www.frenchsite.com'. The 'if' statement is always resulting in false.
I am trying to pass on an email from a user to the default from: field so that it looks like it's coming directly from them. Here is what I have right now. Is there any way of bringing in a dynamic variable into the default from field?
class IntroMailer < ActionMailer::Base
default from: "Me#gmail.com"
def intro_email(intro)
#intro = intro
mail(to: #intro.person1_email, subject: 'Testing Intro Email')
end
end
You can override this in the Mailer action's mail method:
class IntroMailer < ActionMailer::Base
default from: "Me#gmail.com"
def intro_email(intro, current_user)
mail(to: intro.person1_email, subject: 'Testing Intro Email', from: current_user.email)
end
end
but a WARNING. Email clients, like Google, are pretty smart at detecting spam. If they see that a specific SMTP server is sending out emails with lots of different 'from' attributes, your spam rating will go up and your emails will be filtered out by spam filters. To get around this, choose one or two default from emails (e.g. support#mywebsite.com & jobs#mywebsite.com) that fit the email's type, and then add a dynamic reply_to attribute instead.
class IntroMailer < ActionMailer::Base
default from: "ourteam#oursite.com"
def intro_email(intro, current_user)
mail(to: intro.person1_email, subject: 'Testing Intro Email', reply_to: full_from(current_user))
end
private
def full_from(user)
address = Mail::Address.new user.email
address.display_name = user.full_name
address.format
end
end
Actually not, it doesn't work at all in Rails 5.XX
There is the following code for sending email asynchronously:
class OrderMailer < ActionMailer::Base
default from: "some mail"
def send_order_info(order)
#order = order
mail(to: Settings.report_email, subject: "Some subject")
end
#handle_asynchronously :send_order_info
end
It code works, but if I remove comment from 'handle_asynchronously' line I can't send any email. What is the trouble? How can I fix it? Thanks.
if you want to send email in background then do
OrderMailer.delay.send_order_info(#order)