Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/22.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
HTML电子邮件缺少附件_Html_Ruby_Email - Fatal编程技术网

HTML电子邮件缺少附件

HTML电子邮件缺少附件,html,ruby,email,Html,Ruby,Email,当我使用Ruby 1.92发送HTML电子邮件时,附件不会显示在某些电子邮件客户端中。附件应为pdf文件。我可以在exchange服务器上的Outlook 2010中看到附件,但在yahoo web mail中看不到 如果我简单地禁用HTML主体,一切都可以正常工作 代码如下: require 'mail' body_text = File.read('body.html') subject_text = File.read("subject.txt") Mail.defaults do

当我使用Ruby 1.92发送HTML电子邮件时,附件不会显示在某些电子邮件客户端中。附件应为pdf文件。我可以在exchange服务器上的Outlook 2010中看到附件,但在yahoo web mail中看不到

如果我简单地禁用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, <br />
<br />
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<br />
Technical Details:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sent from: Server_Name<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sent To: rep_id<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Original Email: to_email<br />
<br />
Helpdesk Please forward all enquiries to so and so<br />
<br />
<img src="http://www.geiger.com/logo.gif" /></p>
</body>
</html>

你好,

此电子邮件由盖革发送,包含您的A/R账龄报告。如有任何问题,请致电盖革帮助热线207-755-2510
技术细节:
发送自:服务器名称
发送至:代表id
原始电子邮件:发送至\u电子邮件

帮助台请将所有查询转发给某某

以下是message.to_的输出:

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, <br />

<br />

This email was sent from consoto and contains your  report for Nov 2011. For any questions please call the consoto helpdesk @ 207-755-2510<br />

Technical Details:<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sent from: GBFA100016<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Sent To: BDB<br />

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Original Email: WSTAPLES@consoto.COM<br />

<br />

Helpdesk Please forward all enquiries to Wesley Staples or Shawn White<br />

<br />

<img src="http://www.consoto.com/logo.gif" /></p>

</body>

</html>





----==_mimepart_4ecba22c550e5_1cec974ab416812--
日期:2011年11月22日星期二08:22:52-0500
发件人:wstaples@consoto.com
致:WSTAPLES@consoto.COM
消息ID:
主题:你2011年11月的报告——康索托!
Mime版本:1.0
内容类型:多部分/备选;
边界=“-->=”mimepart_4ecba22c550e5_1cec974ab416812”;
字符集=UTF-8
内容传输编码:7bit
----==_mimepart_4ecba22c550e5_1cec974ab416812
日期:2011年11月22日星期二08:22:52-0500
Mime版本:1.0
内容类型:文本/纯文本;
字符集=UTF-8;
filename=test\u attachment.txt
内容传输编码:7bit
内容处置:附件;
filename=test\u attachment.txt
内容ID:
这是一个测试
----==_mimepart_4ecba22c550e5_1cec974ab416812
日期:2011年11月22日星期二08:22:52-0500
Mime版本:1.0
内容类型:text/html;
字符集=UTF-8
内容传输编码:7bit
内容ID:
你好,

此电子邮件由consoto发送,包含您2011年11月的报告。如有任何疑问,请致电consoto帮助热线@207-755-2510
技术细节:
发送人:GBFA100016
发送至:BDB
原始电子邮件:WSTAPLES@consoto.COM

帮助台请将所有查询转发给Wesley Staples或Shawn White

----==_mimepart_4ecba22c550e5_1cec974ab416812--
问题在于您的

Content-Type: multipart/alternative;
当这些邮件的内容类型为“multipart/alternative”和附件时,某些邮件发送程序不会正确解析这些邮件。在这种情况下,您必须使用以下结构创建消息:

 - multipart/mixed
  - multipart/alternative
 ...
您可以这样做:

unless mail_attachments.blank?
  mail.part :content_type => "multipart/alternative"  do |p|
    p.text_part = text_part
    p.html_part = html_part
  end
  mail_attachments.each do |file|
    mail.add_file file.local_path
  end
else
  mail.text_part = text_part
  mail.html_part = html_part
end

可能是一些客户端将其作为垃圾邮件删除?这是什么邮件库?也许问题应该指向该库的联系信息?在一个正确看到消息的客户机上,您可以查看原始源(包括标题)并发布完整的原始消息吗?如果您正在使用,则发布
消息的输出,是的,这是github.com/mikel/mail gem。这是message.to_sFWIW的输出,有很多带有附件的bug。谢谢你让我走上正轨。多亏了你,我在自述文件中找到了这一部分,其中有另一个例子: