2011-09-21 93 views
2

以下问题:每当我尝试通过导轨发送HTML电子邮件时,它都以内容为附件的空电子邮件到达我的googlemail-address。通过rails发送的HTML电子邮件以附件的形式到达

我不太确定我在做什么错在这里。

设置如下:

/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! 

这是我Googlemail电子邮件账户什么到达:

inbox

第一封电子邮件是什么样子与该html.erb和文本.erb激活,第二个只有text.erb。 忽略用户名“根”,这是由于后缀重写,因为实际的邮件是另一台服务器上的(从轨服务器的邮件发送给哪个然后实际​​邮件他们的邮件服务器 - 不是我的设置;)

下面是从第一封电子邮件的原始数据:

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: <[email protected]_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 [email protected]_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 [email protected]_server) [email protected]_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" <[email protected]_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-- 

回答

1

好了,找到了答案:组装的电子邮件不包括边界neccessary以上版本。但是,

mail(:to => '[email protected]') 

将工作并设置正确的边界。

3

不知道关于Ruby和或导轨什么,但我知道一点关于MIME。你的顶级Content-Type标题应该是:

Content-Type: multipart/alternative;boundary="--==_mimepart_4e79c96a1adc0_2ba53f7fe85ced90437f9" 
+0

嗯,我发现这个错误报告:https://rails.lighthouseapp.com/projects/8994/tickets/6657然而,我没有找到一个结论说,错误... – Rhywden

+0

对于后代,上述灯塔票被迁移到https://github.com/rails/rails/issues/985,关闭,并由@Rhywden作为https://github.com/rails/rails/pull/3090重新打开,并以相同的分辨率关闭作为Rhywden的解决方案:不要使用旧的API,它在Rails 3.2中被删除了。 – Yogh

相关问题