将带有附件(html文件)的电子邮件发送到Gmail时,不会发送电子邮件正文。如果我注释掉下面的附件设置就可以了。如果发生电子邮件没有任何附件,它就可以了。
我测试过只有在文件扩展名为“html”时才会引发问题。其他文件如log,png都可以。
如何在发送邮件功能中正确发送 .html
文件?
更新:我从收到的电子邮件中添加了摘录,电子邮件正文作为中间mimepart存在。搜索Content-ID: <4fdfd7725ba26_a0c1a825dc8363d@RATionalxp.mail>
def email_it(body, subject, to, from, attachment_to_send)
$smtp = 'mail.com.au'
$smtp_port = 25
body_with_footer = body +Email_footer
Pony.mail(
:to => to,
:from => from,
:subject => subject,
:body => Nokogiri::HTML(body_with_footer).text,
:html_body => body_with_footer,
:attachments => attachment_to_send,
:via => :smtp,
:via_options => {
:address => $smtp,
:port => $smtp_port,
:enable_starttls_auto => false
}
)
end
从收到的电子邮件中摘录
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_4fdfd77251dac_a0c1a825dc83328";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_4fdfd77251dac_a0c1a825dc83328
Date: Tue, 19 Jun 2012 11:35:46 +1000
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8
Content-Transfer-Encoding: base64
Content-ID: <4fdfd7725ba26_a0c1a825dc8358f@RATionalxp.mail>
QW50wqBydW7CoG5hbWXCoMKgOsKgRWR1bWF0ZV91cGdyYWRlX211bHRpwqAo
ZXhwcmVzcylPdmVyYWxswqByZXN1bHQ6wqBmYWlswqBBbnTCoHJ1bsKgdG9v
azrCoG5vYm9kecKga25vd3PCoDstKcKgUmVzdG9yaW5nwqBmcm9twqAvdmFy
L2xpYi9lZHVtYXRlL2JkcnMvbG9xdWF0L2RhdGFiYXNlcy93ZWVrbHkvTE9R
VUFULjAuZGIyaW5zdDEuTk9ERTAwMDAuQ0FUTjAwMDAuMjAxMjA2MTAwMjMw
MDYuMDAxVGltZXN0YW1wwqBvZsKgYmFja3VwwqBpbWFnZcKgaXM6wqAxMMKg
SnVuwqAyMDEywqAwMjozMERhdGFiYXNlwqBSQVRJT05BTMKgcmVzdG9yZWTC
oHN1Y2Nlc3NmdWxsecKgZnJvbcKgZGF0YWJhc2U6wqBMT1FVQVRyZXN0b3Jl
wqB0b29rOsKgMDowMDozOC0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t
LURldGFpbHPCoGZvcsKgYWxswqBSYXRpb25hbMKgdGVzdMKgc3VpdHMtLS0t
LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS1FZHVtYXRlX3VwZ3JhZGU6wqBs
b2fCoGZpbGXCoG5vdMKgY3JlYXRlZC7CoEVycm9ywqBpbsKgcHJldmlvdXPC
oHRlc3TCoHN1aXTCoChzdG9wT25GYWlsdXJlPSd0cnVlJynCoG9ywqBpbsKg
YW50wqBydW7CoGl0c2VsZi5Qb3dlcmVkIGJ5IEVkdVRlc3RlciBodHRwOi8v
MTAuMC4wLjUw
----==_mimepart_4fdfd77251dac_a0c1a825dc83328
Date: Tue, 19 Jun 2012 11:35:46 +1000
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <4fdfd7725ba26_a0c1a825dc8363d@RATionalxp.mail>
Ant run name : Edumate_upgrade_multi (express)<BR>Overall result: fail<BR> <BR>Ant run took: nobody knows ;-)<BR> <BR>Restoring from /var/lib/edumate/bdrs/loquat/databases/weekly/LOQUAT.0.db2inst1.NODE0000.CATN0000.20120610023006.001<BR>Timestamp of backup image is: 10 Jun 2012 02:30<BR>Database RATIONAL restored successfully from database: LOQUAT<BR>restore took: 0:00:38<BR><BR><BR>------------------------------<BR>Details for all Rational test suits<BR>------------------------------<BR><BR>Edumate_upgrade: log file not created. Error in previous test suit (stopOnFailure='true') or in ant run itself.<BR><BR><HR><BR>Powered by EduTester http://10.0.0.50
----==_mimepart_4fdfd77251dac_a0c1a825dc83328
Date: Tue, 19 Jun 2012 11:35:46 +1000
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8;
filename=rational_ft_logframe.html
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=rational_ft_logframe.html
Content-ID: <4fdfd77259308_a0c1a825dc834d0@RATionalxp.mail>
<HTML>
<HEAD>
<META HTTP-EQUIV="charset" CONTENT="utf-8">
来自小马谷歌小组(不是我的话)
我有一个类似但更简单的例子。
Pony.mail to: 'me@test.com',
from: 'test@test.com',
subject: 'test attachments',
html_body: '<p>HTML</p>',
body: 'Text',
attachments: { File.basename(a_file_path) => File.read(a_file_path) }
我认为内容类型和边界没有正确设置。使用上面的代码,我只会看到附件,我将看不到HTML或文本正文,尽管它们正在正确发送。如果我查看OSX Mail上的备选方案(Option-Command-),我可以看到它们,并且它们正确显示。 content-type设置为multipart / alternative,没有Content-Disposition。我相信在这种情况下,我们发送html,纯文本和附件作为替代品,而不是带有附件的2个替代品,我认为这是混合的,尽管设置内容类型multipart / mixed似乎不起作用要么:所有3个都相互串联。
答案 0 :(得分:1)
我的解决方法是在附加之前将.htm(l)文件重命名为.txt。
答案 1 :(得分:1)
对我来说,它的工作原理是添加
headers: { "Content-Type" => "multipart/mixed" }
作为Pony.mail的参数。
答案 2 :(得分:-1)
将此附件放在via选项下 像这样
Pony.mail to: 'me@test.com',
from: 'test@test.com',
subject: 'test attachments',
html_body: '<p>HTML</p>',
body: 'Text',
:via_options => { :port => '25',
:address => 'smtp.gmail.com',
:enable_starttls_auto => true,
:attachments: { File.basename(a_file_path) => File.read(a_file_path)}
}