I have a mailer that I can see in my log is getting sent, but the email body does not contain anything from the mailer view.
It's due to the fact that I've put things in subfolders and i've tried using :template_path
in my mail
function but to no avail.
app/mailers/marketing/marketing_mailer.rb
class Marketing::MarketingMailer < ActionMailer::Base
require 'mail'
address = Mail::Address.new "[email protected]" # ex: "[email protected]"
address.display_name = "Text" # ex: "John Doe"
# Set the From or Reply-To header to the following:
address.format # returns "John Doe <[email protected]>"
default from: address
# Sends an email when someone fills out the contact form
def contact(name, email, message)
@name = name
@email = email
@message = message
mail(:subject => "Test", :to => '[email protected]', :reply_to => @email) # <== I've tried using :template_path => 'marketing', 'marketing/marketing_mailer', etc, but none worked.
end
end
/app/views/marketing/marketing_mailer/contact.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type" />
</head>
<body>
<p>Name: <%= @name %></p>
<p>Email: <%= @email %></p>
<p>Message: <%= @message %></p>
</body>
</html>
I noticed that devise has mailer views inside /views/devise/mailers/... so I know it's possible, but i'm not sure how.
Have you tried mail with {:template_path => 'marketing/marketing_mailer, :template_name =>'contact'} ?
The template name probably expects the namespace in the filename somehow
Does it work without the template Rendering
class Marketing::MarketingMailer < ActionMailer::Base
def welcome_email(user, email_body)
mail(to: user.email,
body: email_body,
content_type: "text/html",
subject: "Already rendered!")
end
end
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