I've tried every possibility I can think of but just keep getting the same error when sending data through a form to a rails mailer. Any idea why I'm getting the "No template found for MailerController#sign_up" response at the bottom?
routes.rb
scope '/mailer' do
post '/signup' => 'mailer#sign_up'
end
app/controller/mailer_controller.rb
class MailerController < ApplicationController
def sign_up
#Create user object
#user = { first_name: params[:first_name],
last_name: params[:last_name],
email: params[:email],
package: params[:package_type],
username: params[:username],
followers: params[:followers],
age: params[:age],
hashtags: params[:hashtags],
comments: params[:comments]
}
AppMailer.sign_up(#user).deliver_now
end
end
app/mailers/app_mailer.rb
class AppMailer < ActionMailer::Base
default from: 'redacted_email'
def sign_up(user)
#user = user
mail(to: "redacted_email", from: #user['email'], subject: 'Sign Up | IAS')
end
end
app/views/app_mailer/sign_up.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<strong>First Name: </strong><p><%= #user[:first_name] %></p><br>
<strong>Last Name: </strong><p><%= #user[:last_name] %></p><br>
<strong>Email: </strong><p><%= #user[:email] %></p><br>
<strong>Package: </strong><p><%= #user[:package] %></p><br>
<strong>Username: </strong><p><%= #user[:username] %></p><br>
<strong>Current Followers: </strong><p><%= #user[:followers] %></p><br>
<strong>Age: </strong><p><%= #user[:age] %></p><br><br>
<strong>Hashtags: </strong><p><%= #user[:hashtags] %></p><br><br>
<strong>Comments: </strong><p><%= #user[:comments] %></p>
</body>
</html>
server response
Started POST "/mailer/signup" for ::1 at 2017-10-23 15:15:48 -0400
Processing by MailerController#sign_up as HTML
Parameters: {redacted but all going through successfully}
Rendering app_mailer/sign_up.html.erb
Rendered app_mailer/sign_up.html.erb (1.7ms)
Rendering app_mailer/sign_up.text.erb
Rendered app_mailer/sign_up.text.erb (0.6ms)
AppMailer#sign_up: processed outbound mail in 395.7ms
Sent mail to redacted#email.com (25.0ms)
Date: Mon, 23 Oct 2017 15:15:49 -0400
To: redacted#email.com
Message-ID: <59ee3fe573c8_17c8e3fcc17436908788c#Sephs-MBP-5.fios-router.home.mail>
Subject: Sign Up | IAS
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_59ee3fe529f6_17c8e3fcc1743690877b7";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_59ee3fe529f6_17c8e3fcc1743690877b7
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Mail unable to send. Please contact IAS Support.
----==_mimepart_59ee3fe529f6_17c8e3fcc1743690877b7
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<strong>First Name: </strong><p>redacted</p><br>
<strong>Last Name: </strong><p>redacted</p><br>
<strong>Email: </strong><p>redacted</p><br>
<strong>Package: </strong><p>$25/mo | Basic</p><br>
<strong>Username: </strong><p>redacted</p><br>
<strong>Current Followers: </strong><p>58.5k</p><br>
<strong>Age: </strong><p>1</p><br><br>
<strong>Hashtags: </strong><p>hash tagsss</p><br><br>
<strong>Comments: </strong><p>commentssss</p>
</body>
</html>
----==_mimepart_59ee3fe529f6_17c8e3fcc1743690877b7--
No template found for MailerController#sign_up, rendering head :no_content
Completed 204 No Content in 484ms
Your issue is that you are missing the view for the controller not for the mailer. The mailer is working wonderfully. The issue is that you are sending the mail through an HTTP POST to the controller. After sending the request, it is not sure what it needs to respond to.
Is this a JS / JSON request to the controller? Adding something like:
render json: { status: 'ok' }
to the end of your action should solve the issue.
Related
So I am testing a mailer gem(letter_opener) for my app to view emails on the browser.
So i have my notifications_controller(generated by scaffolding).
Then my mailer:
notification_mailer
class NotificationMailer < ApplicationMailer
default to: -> { "somelist#postbox.tu" },
from: -> { "info#postbox.tut" }
def notification_mailer(notification)
#notification = notification
#url = "http://postbox.tut/"
mail(:subject => "New Notification")
end
end
This is my views/notification_mailer/notification_mailer view
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></pre>
<h1>Notification email.</h1>
<h2><%= #notification.headline %></h2>
<pre>
<%= #notification.content %>
This email was sent out to you, because you are subscribed to the postbox-mailing-list.
If you want to unscribscribe, please use this url: <%= #url %>.
Instead of opening a new tab (containing the rendered email) like I'm having yesterday now I can't. But my rails console says:
Started POST "/notifications" for 127.0.0.1 at 2018-10-10 15:17:56 +0800
Processing by NotificationsController#create as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"MgfddL8EHhDylDDVHqsvYLlQ2HO0fB1J9amMpty1HDqsjJGCJx0fpBfnlvRVeOUtxMc8Seq8L8lsxeZeGg3Aww==", "notification"=>{"headline"=>"Don", "content"=>"pogi pogi no mi\r\n"}, "commit"=>"Create Notification"}
Rendering notification_mailer/notification_mailer.html.erb within layouts/mailer
Rendered notification_mailer/notification_mailer.html.erb within layouts/mailer (0.7ms)
NotificationMailer#notification_mailer: processed outbound mail in 33.5ms
Sent mail to somelist#postbox.tu (23.4ms)
Date: Wed, 10 Oct 2018 15:17:56 +0800
From: info#postbox.tut
To: somelist#postbox.tu
Message-ID: <5bbda7a42ca92_5e7f2b0fe9be8a10789b3#don-300E4C-300E5C-300E7C.mail>
Subject: New Notification
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
/* Email styles need to be inline */
</style>
</head>
<body>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></pre>
<h1>Notification email.</h1>
<h2>Don</h2>
<pre>
pogi pogi no mi
This email was sent out to you, because you are subscribed to the postbox-mailing-list.
If you want to unscribscribe, please use this url: http://postbox.tut/.
</body>
</html>
Checking my tmp folder the mail is being generated. Now what's happening is no browser is being opened but a blank visual studio code file always opened after creating a new post.
I just figured this one out. Seems like I accidentally changed my default html viewer into my text editor.
I am having an issue sending some emails, while others seem to work fine.
it seems like when i am using my views they are not sending, here is an a mail i have defined that just passes a body that sending just fine
def send_contact_email params
mail({from: params[:email],
to: 'inquiries#gmail.ca',
body: params[:message],
content_type: "text/html",
subject: "Inquiry from [#{ params[:name] }]"})
end
UserMailer.send_contact_email(params).deliver_now
here is what welcome looks like..this one does not work..
def welcome user, token
#resource = user
#token = token
mail({ to: user.email,
content_type: "text/html",
subject: "Thankyou!"})
end
UserMailer.welcome(u,hashed_token).deliver_now
here is what i get in the logs
UserMailer#welcome: processed outbound mail in 13.9ms
Sent mail to email#gmail.com (10364.1ms)
Date: Sat, 25 Nov 2017 19:39:19 +1100
From: no-reply#gmail.cl
To: email#gmail.com
Message-ID: <5a192c37982fc_a9663ff3cec3e51845790#mac.local.mail>
Subject: Gracias!
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>The Project | Email Template</title>
</head>
<body style="margin: 0; padding: 0;">
<p>Hola email#gmail.com!</p>
<p>Se ha solicitado cambiar tu contrasena. Puedes hacerlo a traves del siguiente link.</p>
<button style="color:white; background:#FF5722; border:0; border-radius:0; padding:15px; font-size:16px;"><a style="color:white; text-decoration: none;" href="http://localhost:3000/users/password/edit?reset_password_token=a9d57947ffb8c077a2b58239d0c6afec91e7c7bb9424c36cb362d6682341c086">Cambiar contrasena</a></button>
<p>Si no lo solicito, ignore este correo electronico.</p>
<p>Su contrasena no cambiara hasta que acceda al link de arriba y cree una nueva.</p>
</body>
</html>
=> #<Mail::Message:70316446670780, Multipart: false, Headers: <Date: Sat, 25 Nov 2017 19:39:19 +1100>, <From: no-reply#gmail.cl>, <To: email#gmail.com>, <Message-ID: <5a192c37982fc_a9663ff3cec3e51845790#mac.local.mail>>, <Subject: Gracias!>, <Mime-Version: 1.0>, <Content-Type: text/html>, <Content-Transfer-Encoding: 7bit>>
it appears as though the mail gets generated, I am calling deliver_now on the response, but it never hits the inbox via mailjet...could it be the content of the view that is some how keeping it from delivering?
I am using rails 4.2.8 and ruby 2.4.0
Thanks in advance!
EDIT this is my action_mailer config from development.rb
# Tell Action Mailer not to deliver emails to the real world.
# The :test delivery method accumulates sent emails in the
# ActionMailer::Base.deliveries array.
config.action_mailer.perform_deliveries = true
config.action_mailer.preview_path = "#{Rails.root}/test/mailers/previews"
config.action_mailer.raise_delivery_errors = true
config.action_mailer.default_url_options = { :host => 'localhost', :port => 3000 }
config.action_mailer.delivery_method = :mailjet
config/initializers/mailjet.rb is defined with the key and secret for the API and gem 'mailjet' is in the Gemfile
I am trying to send emails through using sendgrid template. But still sent, standard template.
def send_test_email(user)
#user = user
sendgrid_unique_args "filters" => {
templates" => {
"settings" => {
"enable" => 1,
"template_id" => "5e4a1ef6-a948-455f-b194-cec87ef88b0e"
}
}
}
mail( :to => #user.email,
:subject => 'Thanks for signing up for our amazing app' )
end
After sending
Sent mail to test#ya.net (699.1ms)
Date: Thu, 13 Aug 2015 10:00:04 +0300
From: example#example.com
To: test#ya.net
Message-ID: <55cc407412764_23922fba2642131f#Vlad.mail>
Subject: Thanks for signing up for our amazing app
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
X-SMTPAPI: {"unique_args": {"filters": {"templates": {"settings":
{"enable":1,"template_id": "5e4a1ef6-a948-455f-b194-cec87ef88b0e"}}}}}
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Thanks for signing up, Jovani!</h1>
<p>Thanks for joining and have a great day! Now sign in and do
awesome things!</p>
</body>
</html>
How do I make that poisoned sendgrid template?
Your question does not clearly state the problem, but one thing I did notice is that your HTML does not have <%body%> which send grid needs in order to work with templates properly.
I'm working on an application with Rails 4 on Ruby 2.0.0. The application sends out an email after a registration in Devise.
This is the code that sends the email:
app/models/sponsor.rb:
after_create :send_email_to_admin
private
def send_email_to_admin
AdminMailer.new_sponsor_email(self).deliver
end
app/mailers/admin_mailer.rb
class AdminMailer < ActionMailer::Base
default to: '**removed**'
def new_sponsor_email(sponsor)
#sponsor = sponsor
p #sponsor
mail(subject: "New Sponsor Registration")
end
end
And this is the generated email from the log file:
Sent mail to **removed** (725.5ms)
Date: Mon, 02 Sep 2013 15:01:03 -0400
From: **removed**
To: **removed**
Message-ID: <5224e06f4dddd_2e5a3fa0452dcfd874597#centaur.mail>
Subject: New Sponsor Registration
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
A new sponsor has signed up!
==========================
----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<!DOCTYPE html>
<html lang='en'>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type'>
</head>
<body>
<h1>A new sponsor has signed up!</h1>
</body>
</html>
----==_mimepart_5224e06f4cca1_2e5a3fa0452dcfd87441a--
when I try to test the code by creating a sponsor, I just get this error:
Net::SMTPSyntaxError in Devise::RegistrationsController#create
501 5.5.4 Invalid argument
My understanding is that this is typically because the email is and invalid email, but all of my emails are very simple, in the format of name#domain.tld and no-reply#domain.tld.
The issue seemed to be that I was using "domain" in my smtp_settings. When I removed that, I was able to send emails from both Mailgun and Gmail
I want to send html email's with my Rails Mailer.
Could be multipart/alternative or only text/html.
Problem is, when I send an email with a link, it appears well on Gmail, but not so good in Thunderbird.
The problem is, that in Thunderbird, the link is 'not clickable' - it's highlighted like a link, but clicking on it does nothing.
Links on other mails (not sent from Rails Mailer) work flawlessly.
So my question is: how to properly send an html email, so it will be viewed properly?
Mailer code:
class MyMailer < ActionMailer::Base
def mailing_delivery(email, subject)
mail(:to => email, :subject => subject)
end
Mail view:
# mailing_delivery.html.haml
%p
Thanks! Its your mailer!
%p
= link_to "Google", "google.com"
Source of email (some parts cut-out):
Date: Thu, 18 Aug 2011 14:32:34 +0200
From: xxx
To: xxx
Message-ID: <4e4d0662bf96e_41024be957a57974#xxx.mail>
Subject: Super news!
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
X-O2-Trust: 2, 64
X-O2-SPF: neutral
<p>
Thanks! It's your mailer!
</p>
<p>
Google
</p>
Of course Rails 3. Thunderbird 5.0, but that's not the issue - because somehow other mails show up good.. And I don't think it's app specific.
What should I do, to make this work?
Edit: I tried to change the 'content-transfer-encoding' header with no success, by doing mail(:to => email, :subject => subject, "Content-Transfer-Encoding" => value) or in class default "Content-Transfer-Encoding" => value with no luck.. how to change that?
Emails that works good under Thunderbird have Content-Transfer-Encoding: quoted-printable (or eventually base64) so maybe that's the issue? How do I change it?
Edit 2: I managed to change the Content-Transfer-Encoding to quoted-printable but it's cutting the content, like this:
Date: Thu, 18 Aug 2011 22:04:21 +0200
From: xxx
To: xxx
Message-ID: <4e4d704557839_151c4e4957c2132e#xxx.mail>
Subject: Super news!
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
X-O2-Trust: 2, 63
X-O2-SPF: neutral
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://ww=
w.w3.org/TR/html4/loose.dtd">
<html>
<body>
<p>
Thanks! It's your mailer!
</p>
<p>
<a href=
One other thing: why is there a newline in Content-Type ? I didn't see it in other (working good) mails. How I can get rid of it?
Maybe it'll work if you fix your html. So instead of just having:
<p>
Thanks! It's your mailer!
</p>
<p>
Google
</p>
try:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<body>
<p>
Thanks! It's your mailer!
</p>
<p>
Google
</p>
</body>
</html>