Rails mail render empty mail body in production - ruby-on-rails

I use rails Rails 3.2.3 and Resque to send an emails.
For some strange reason emails on production sended with empty body.
I try reproduce problem localy but with no luck.
production log does not have anything strange
Sent mail to somemail#rambler.ru (730ms)
Rendered user_mailer/_activation_email.html.erb (0.8ms)
Rendered user_mailer/activate_service_provider_with_email.html.erb within layouts/user_mailer (83.2ms)
Sent mail to somemail#rambler.ru (737ms)
Rendered user_mailer/_activation_email.html.erb (0.7ms)
Rendered user_mailer/activate_service_provider_with_email.html.erb within layouts/user_mailer (83.3ms)
Sent mail to somemail#rambler.ru (740ms)
Rendered user_mailer/discount.html.erb within layouts/user_mailer (231.6ms)
Sent mail to somemail#rambler.ru (536ms)
Starting the New Relic Agent.
Installed New Relic Browser Monitoring middleware
Creating scope :near. Overwriting existing method ServiceProvider.near.
Connected to NewRelic Service at collector-2.newrelic.com
Can anybody suggest what should I check - cache e.t.c to find problem ...
Email should contain html inside but I get plain text content type
Here is mail text:
Delivered-To: somemail#gmail.com
Received: by 11.11.66.777 with SMTP id c8csp32365iei;
Fri, 6 Jul 2012 06:34:44 -0700 (PDT)
Received: by 11.22.333.444 with SMTP id lv8mr2489460igc.41.1341581684021;
Fri, 06 Jul 2012 06:34:44 -0700 (PDT)
Return-Path: <noreply#oursite.ua>
Received: from soursite.ru (oursite.ru. [184.106.242.18])
by mx.google.com with ESMTPS id vb2si4216338igc.71.2012.07.06.06.34.43
(version=TLSv1/SSLv3 cipher=OTHER);
Fri, 06 Jul 2012 06:34:44 -0700 (PDT)
Received-SPF: pass (google.com: domain of noreply#oursite.ua designates 111.11.111.11 as permitted sender) client-ip=123.456.78.90;
Authentication-Results: mx.google.com; spf=pass (google.com: domain of noreply#oursite.ua designates 123.456.78.908 as permitted sender) smtp.mail=noreply#oursite.ua
Received: from localhost ([127.0.0.1] helo=localhost.localdomain)
by oursite.ru with esmtp (Exim 4.71)
(envelope-from <noreply#oursite.ua>)
id 1Sn8k3-00086o-Vt
for somemail#gmail.com; Fri, 06 Jul 2012 13:38:40 +0000
Date: Fri, 06 Jul 2012 13:38:39 +0000
From: noreply#oursite.ua
To: somemail#gmail.com
Message-ID: <4ff6ea5fb7942_79c0f9c45069741#OURSITE.ru.mail>
Subject: =?UTF-8?Q?=D0=9C=D1=8B?=
=?UTF-8?Q?_=D0=BF=D1=80=D0=B8=D0=B2=D0=BE=D0=B4=D0=B8=D0=BC_=D0=BA?=
=?UTF-8?Q?_=D0=92=D0=B0=D0=BC?=
=?UTF-8?Q?_=D0=BA=D0=BB=D0=B8=D0=B5=D0=BD=D1=82=D0=BE=D0=B2_=D0=B8?=
=?UTF-8?Q?_=D0=BE=D0=BF=D0=BB=D0=B0=D1=87=D0=B8=D0=B2=D0=B0=D0=B5=D0=BC?=
=?UTF-8?Q?_=D0=B8=D0=BC_=D1=83=D1=81=D0=BB=D1=83=D0=B3=D0=B8?=
=?UTF-8?Q?_=D0=92=D0=B0=D1=88=D0=B5=D0=B3=D0=BE?=
=?UTF-8?Q?_=D1=81=D0=B0=D0=BB=D0=BE=D0=BD=D0=B0:?=
=?UTF-8?Q?_=D0=9F=D0=B0=D1=80=D1=82=D0=BD=D0=B5=D1=80=D1=81=D0=BA=D0=B0=D1=8F?=
=?UTF-8?Q?_=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B0?=
=?UTF-8?Q?_=D0=BE=D1=82?=
=?UTF- ?Q?_=D0=98=D0=BD=D1=82=D0=B5=D1=80=D0=BD=D0=B5=D1=82-=D0=BF=D0=BE=D1=80=D1=82=D0=B0=D0=BB= D0=B0?=
=?UTF-8?Q?=
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
And here is correct mail which I get on development
Return-Path: <noreply#oursite.ua>
Received: from [11.2.2.21] (HELO mx21.rambler.ru)
by mail43.rambler.ru (rmaild SMTP 1.3.41)
with ESMTP id 44865232 for someguy#rambler.ru; Fri, 06 Jul 2012 17:24:06 +0400
Received: from oursite.ru (oursite.ru [111.456.111.11])
by mx21.rambler.ru (Postfix) with ESMTP id E6D5ED85F69
for <someguy#rambler.ru>; Fri, 6 Jul 2012 17:24:05 +0400 (MSK)
Received: from localhost ([127.0.0.1] helo=localhost.localdomain)
by oursite.ru with esmtp (Exim 4.71)
(envelope-from <noreply#oursite.ua>)
id 1Sn8Zl-0007up-Cj
for someguy#rambler.ru; Fri, 06 Jul 2012 13:28:01 +0000
Date: Fri, 06 Jul 2012 13:28:01 +0000
From: noreply#oursite.ua
To: someguy#rambler.ru
Message-ID: <4ff6e7e127236_76d3127debc36876#oursite.ru.mail>
Subject: =?UTF-8?Q?=D0=90=D0=BA=D1=82=D0=B8=D0=B2=D0=B0=D1=86=D0=B8=D1=8F?=
=?UTF-8?Q?_=D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82=D0=B0_=D0=B2_oursite?=
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: quoted-printable
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.o=
rg/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=3D"http://www.w3.org/1999/xhtml" xml:lang=3D"en-GB">
<head>
<title>oursite email notification</title>
<meta http-equiv=3D"Content-Type" content=3D"application/xhtml+xml; char=
set=3Dutf-8" />
<meta name=3D"description" content=3D"oursite!" />
<meta name=3D"keywords" content=3D"" />
<meta name=3D"robots" content=3D"index, follow" />
<meta http-equiv=3D"X-UA-Compatible" content=3D"IE=3Dedge" /> <!-- IE=
9 rounded corners -->
</head>
<body>
=
<div style=3D"border:4px solid #a90e15; width:600px; padding:20px; ba=
ckground-color:#fff; font-family:Helvetica, Arial, sans-serif;">
<div style=3D"color:#a90e15; font-size:60px; letter-spacing:-1px;=
font-weight:lighter;">Style <span style=3D"background-color:#a90e15; col=
or:#fff; font-size: 40px; padding:10px; font-weight:bold;">Up</span></div=
><br />
<div style=3D"color:#000; font-size:14px;">
=
=D0=94=D0=BE=D0=B1=D1=80=D0=BE =D0=BF=D0=BE=D0=B6=D0=B0=
=D0=BB=D0=BE=D0=B2=D0=B0=D1=82=D1=8C =D0=B2 oursite, DeleteThis!<br />
=D0=94=D0=BB=D1=8F =D1=82=D0=BE=D0=B3=D0=BE =D1=87=D1=82=D0=BE=D0=
=B1=D1=8B =D0=B0=D0=BA=D1=82=D0=B8=D0=B2=D0=B8=D1=80=D0=BE=D0=B2=D0=B0=D1=
=82=D1=8C =D0=92=D0=B0=D1=88 =D0=B0=D0=BA=D0=BA=D0=B0=D1=83=D0=BD=D1=82 =D0=
=BF=D1=80=D0=BE=D0=B9=D0=B4=D0=B8=D1=82=D0=B5 =D0=BF=D0=BE =D1=81=D1=81=D1=
=8B=D0=BB=D0=BA=D0=B5 <a href=3D"http://kiev.oursite.ua/activate/S6oqGyan=
66i83NoTNUI">http://kiev.oursite.ua/activate/S6oqGyan66i83NoTNUI</a>.<br =
/>
<br />
<br />
=
</div>
</div><!-- end of accom div -->
<div style=3D"color:#000; background-color:#FBF5E5; font-size:12px; w=
idth:628px; padding:10px; text-align:center; font-family:Helvetica, Arial=
, sans-serif;">
=D0=93=D1=80=D1=83=D0=BF=D0=BF=D0=B0 oursite! <a href=3D"http://v=
kontakte.ru/club1111409799" style=3D"color:#000; font-weight:bold;">=D0=B2=D0=
=BA=D0=BE=D0=BD=D1=82=D0=B0=D0=BA=D1=82=D0=B5</a><br />
=D0=93=D1=80=D1=83=D0=BF=D0=BF=D0=B0 =D0=B2 <a href=3D"http://www=
.facebook.com/oursite.ru" style=3D"color:#000; font-weight:bold;">faceboo=
k</a><br />
=D0=9D=D0=B0=D1=88=D0=B8 =D0=BD=D0=BE=D0=B2=D0=BE=D1=81=D1=82=D0=B8=
=D0=B2 <a href=3D"https://twitter.com/intent/user?screen_name=3Doursite_=
ru" style=3D"color:#000; font-weight:bold;">twitter</a><br />
<a href=3D"oursite.ua" style=3D"color:#000; font-weight:bold;"></=
a><br /><br />
© 2011 oursite! =
</div>
</body>
</html>

Looks like I find solution.
HTML template for mail contain only <%= render 'some_partial' %>
and nothing else
when I copy text from partial to template it begin render correctly.

Related

Sendgrid template

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.

Test google schema in my gmail account

I'm a starter in Google Schema, I've followed the getting started, but it doesn't work... I've changed to another more simple json-ld, simple actions, but ....
I'm testing with a Django project, in my local, django smtp config to smpt.gmail.com. Same from and to email. I can see the email, but I can't see go-to-action....
This is my original mail:
Return-Path: <XX#gmail.com>
Received: from tomas-H55M-D2H (37.130.151.22.radiocable.net. [37.130.151.22])
by mx.google.com with ESMTPSA id n3sm2456222wix.1.2015.05.12.04.20.07
for <XX#gmail.com>
(version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128);
Tue, 12 May 2015 04:20:07 -0700 (PDT)
MIME-Version: 1.0
Content-Type: text/html; charset="utf-8"
Content-Transfer-Encoding: 7bit
Subject: Testing
From: XX#gmail.com
To: XX#gmail.com
Date: Tue, 12 May 2015 11:20:07 -0000
Message-ID: <20150512112007.23123.78164#tomas-H55M-D2H>
Reply-To: XX#gmail.com
<html>
<head>
<script type="application/ld+json">
{
"#context": "http://schema.org",
"#type": "EmailMessage",
"description": "Check this out",
"action": {
"#type": "ViewAction",
"url": "https://www.youtube.com/watch?v=eH8KwfdkSqU"
}
}
</script>
</head>
<body>
<p>
This a test for a Go-To action in Gmail.
</p>
</body>
</html>

Using Google Mail Actions

So I've been reading about the little action icons in Google Mail and I'm trying to set this up inside Rails 3. I have the template, I have the message itself, I have SMTP set up to Google Mail as well.
According to this article:
http://googleappsdeveloper.blogspot.com/2013/05/introducing-actions-in-inbox-powered-by.html
(read the comments) the only way to test this out is to send the messages from you to you (the sender and recipient have to be the same). Unfortunately, it looks like you still have to DKIM or SPF validate the message as well.
So here's the question: Has anybody been able to test this inside a dev environment? When I use GMail SMTP, I don't get a DKIM signature so it won't show the action icon on the far right.
Message Body:
Received: -
Date: Sat, 22 Feb 2014 15:25:45 -0800
From: me
To: me
Message-ID: <530931f945de6_17c563fc73085e6e86978c#BigMac.local.mail>
Subject: Testing Gmail action Schemas :
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_530931f943db6_17c563fc73085e6e869643";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_530931f943db6_17c563fc73085e6e869643
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
EMAIL CONTENT GOES HERE
----==_mimepart_530931f943db6_17c563fc73085e6e869643
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
<html>
<header>
<div itemscope itemtype="http://schema.org/EmailMessage">
<meta itemprop="description" content="Click here to view your ticket."/>
<div itemprop="action" itemscope itemtype="http://schema.org/ViewAction">
<link itemprop="url" href="https://support.und0.com/tickets/1"/>
<meta itemprop="name" content="View ticket"/>
</div>
</div>
</header>
<body>
<div>EMAIL CONTENT GOES HERE</div>
</body>
</html>
----==_mimepart_530931f943db6_17c563fc73085e6e869643--

ActionMailer responds with "501 5.5.4 Invalid argument"

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

Rails mailer and links not working under Thunderbird

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>

Resources