Reputation: 750
Following problem: Whenever I try to sent a HTML-email through rails, it arrives at my googlemail-adress as an empty email with the content as an attachment.
I'm not quite sure what I'm doing wrong here.
Setup as follows:
/app/mailers/testmail.rb
class Testmail < ActionMailer::Base
default :from => "[email protected]"
default_url_options[:host] = '10.10.8.1'
def email
subject 'Willkommen!'
recipients '[email protected]'
from '[email protected]'
sent_on Time.now
end
end
/app/views/testmail/email.html.erb
<p>Dies ist eine <strong>Testmail!</strong></p>
/app/views/testmail/email.text.erb
Dies ist eine Test-Email!
This is what arrives in my Googlemail-Account:
The first email is what it looks like with with the html.erb and text.erb active, the second one with only text.erb. Ignore the username "root", that's due to a postfix rewrite because of the actual mailer being on another server (emails from the rails server get sent to the mail server which then actually mails them - not my setup ;)
And here's the raw data from the first email:
Delivered-To: [email protected]
Received: by 10.101.108.3 with SMTP id k3cs279048anm;
Wed, 21 Sep 2011 04:24:29 -0700 (PDT)
Received: by 10.204.134.8 with SMTP id h8mr508445bkt.11.1316604268267;
Wed, 21 Sep 2011 04:24:28 -0700 (PDT)
Return-Path: <inet@our_server>
Received: from our_server (our_server. [100.0.0.0])
by mx.google.com with ESMTP id i7si2877863bke.151.2011.09.21.04.24.27;
Wed, 21 Sep 2011 04:24:28 -0700 (PDT)
Received-SPF: neutral (google.com: 100.0.0.0 is neither permitted nor denied by best guess record for domain of inet@our_server) client-ip=100.0.0.0;
Authentication-Results: mx.google.com; spf=neutral (google.com: 100.0.0.0 is neither permitted nor denied by best guess record for domain of inet@our_server) smtp.mail=inet@our_server
Received: from zero (our_server [100.0.0.1])
by our_server (Postfix) with SMTP id 4251724B65
for <[email protected]>; Wed, 21 Sep 2011 13:24:26 +0200 (CEST)
Received: by zero (sSMTP sendmail emulation); Wed, 21 Sep 2011 13:24:26 +0200
From: "root" <inet@our_server>
Date: Wed, 21 Sep 2011 13:24:25 +0200
To: [email protected]
Message-ID: <[email protected]_router.mail>
Subject: Willkommen!
Mime-Version: 1.0
Content-Type: multipart/alternative
Content-Transfer-Encoding: 7bit
----==_mimepart_4e79c96a1adc0_2ba53f7fe85ced90437f9
Date: Wed, 21 Sep 2011 13:24:26 +0200
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content-ID: <[email protected]_router.mail>
Dies ist eine Test-Email!
----==_mimepart_4e79c96a1adc0_2ba53f7fe85ced90437f9
Date: Wed, 21 Sep 2011 13:24:26 +0200
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Content-ID: <[email protected]_router.mail>
<p>Dies ist eine <strong>Testmail!</strong></p>
----==_mimepart_4e79c96a1adc0_2ba53f7fe85ced90437f9--
Upvotes: 2
Views: 536
Reputation: 750
Okay, found the answer: The above version of assembling the email does NOT include the boundary neccessary. However,
mail(:to => '[email protected]')
will work and set the correct boundaries.
Upvotes: 1
Reputation: 3827
Dont know anything about ruby and or rails, but I do know a bit about MIME. Your top level Content-Type
header should be:
Content-Type: multipart/alternative;boundary="--==_mimepart_4e79c96a1adc0_2ba53f7fe85ced90437f9"
Upvotes: 3