以下问题:每当我尝试通过rails发送HTML电子邮件时,它都会将我的googlemail-adress作为空白电子邮件发送到内容作为附件。
我不太确定我在这里做错了什么。
设置如下:
/app/mailers/testmail.rb
class Testmail < ActionMailer::Base
default :from => "our_adress@our.router"
default_url_options[:host] = '10.10.8.1'
def email
subject 'Willkommen!'
recipients 'me@googlemail.com'
from 'our_adress@our.router'
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帐户中的内容:
第一封电子邮件是html.erb和text.erb处于活动状态时的状态,第二封只有text.erb。 忽略用户名“root”,这是由于后缀重写,因为实际的邮件程序在另一台服务器上(来自rails服务器的电子邮件被发送到邮件服务器然后实际邮寄它们 - 而不是我的设置;)
以下是第一封电子邮件中的原始数据:
Delivered-To: me@googlemail.com
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 <me@googlemail.com>; 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: me@googlemail.com
Message-ID: <4e79c96a2ed6b_2ba53f7fe85ced9044023@zero.our_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: <4e79c96a28cbb_2ba53f7fe85ced9043891@zero.our_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: <4e79c96a2bd8d_2ba53f7fe85ced90439a1@zero.our_router.mail>
<p>Dies ist eine <strong>Testmail!</strong></p>
----==_mimepart_4e79c96a1adc0_2ba53f7fe85ced90437f9--
答案 0 :(得分:3)
对ruby和rails没有任何了解,但我确实对MIME有所了解。您的顶级Content-Type
标题应为:
Content-Type: multipart/alternative;boundary="--==_mimepart_4e79c96a1adc0_2ba53f7fe85ced90437f9"
答案 1 :(得分:1)
好的,找到答案:上面组装电子邮件的版本不包括必要的边界。然而,
mail(:to => 'whoever@wheree.ver')
将起作用并设置正确的边界。