当我使用Ruby 1.92发送HTML电子邮件时,某些电子邮件客户端中不显示附件 . 附件应该是pdf文件 . 我可以在Exchange 2010上的Exchange 2010上看到附件,但不能在雅虎Web邮件中看到 .
如果我只是禁用HTML正文,一切正常 .
这是代码:
require 'mail'
body_text = File.read('body.html')
subject_text = File.read("subject.txt")
Mail.defaults do
delivery_method :smtp, { :address => "servername", :port => "25", :user_name => "name", :password => "password", :authentication => 'login'}
end
message = Mail.new do
from ARGV[0]
to ARGV[1]
subject subject_text
# if I comment out this section everything works fine
html_part do
content_type 'text/html; charset=UTF-8'
body body_text
end
add_file ARGV[2]
end
message.deliver!
这是HTML源代码:
<html>
<body>
<p style="font-family:trebuchet ms,helvetica,sans-serif;">Hello,
This email was sent from Geiger and contains your A/R aged report for date. For any questions please call the Geiger helpdesk @ 207-755-2510
Technical Details:
Sent from: Server_Name
Sent To: rep_id
Original Email: to_email
Helpdesk Please forward all enquiries to so and so
<img src="http://www.geiger.com/logo.gif" /></p>
</body>
</html>
这是message.to_s的输出:
Date: Tue, 22 Nov 2011 08:22:52 -0500
From: wstaples@consoto.com
To: WSTAPLES@consoto.COM
Message-ID: <4ecba22c9ecb3_1cec974ab4171df@GBFA100016.mail>
Subject: Your report for November, 2011 - consoto Gets it!
Mime-Version: 1.0
Content-Type: multipart/alternative;
boundary="--==_mimepart_4ecba22c550e5_1cec974ab416812";
charset=UTF-8
Content-Transfer-Encoding: 7bit
----==_mimepart_4ecba22c550e5_1cec974ab416812
Date: Tue, 22 Nov 2011 08:22:52 -0500
Mime-Version: 1.0
Content-Type: text/plain;
charset=UTF-8;
filename=test_attatchment.txt
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename=test_attatchment.txt
Content-ID: <4ecba22c75492_1cec974ab416991@GBFA100016.mail>
This is a test
----==_mimepart_4ecba22c550e5_1cec974ab416812
Date: Tue, 22 Nov 2011 08:22:52 -0500
Mime-Version: 1.0
Content-Type: text/html;
charset=UTF-8
Content-Transfer-Encoding: 7bit
Content-ID: <4ecba22c92576_1cec974ab41707b@GBFA100016.mail>
<html>
<body>
<p style="font-family:trebuchet ms,helvetica,sans-serif;">Hello,
This email was sent from consoto and contains your report for Nov 2011. For any questions please call the consoto helpdesk @ 207-755-2510
Technical Details:
Sent from: GBFA100016
Sent To: BDB
Original Email: WSTAPLES@consoto.COM
Helpdesk Please forward all enquiries to Wesley Staples or Shawn White
<img src="http://www.consoto.com/logo.gif" /></p>
</body>
</html>
----==_mimepart_4ecba22c550e5_1cec974ab416812--
1 回答
问题出在你的身上
当这些邮件的内容类型为“multipart / alternative”和附件时,某些邮件程序不会更正解析邮件 . 在这种情况下,您必须使用此结构创建消息:
你可以这样做: