如何发送长度超过990个字符的csv附件? [英] How to send a csv attachment with lines longer than 990 characters?

查看:177
本文介绍了如何发送长度超过990个字符的csv附件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好的。我认为这个问题与我的rails应用程序有关,但它似乎与电子邮件附件的更深入的工作。

Alright. I thought this problem had something to do with my rails app, but it seems to have to do with the deeper workings of email attachments.

我必须发出一个csv文件从我的rails应用程序到一个仓库,满足我的商店中的订单地点。仓库有一个CSV格式,讽刺的是CSV文件的标题行是超长的(1000+个字符)。

I have to send out a csv file from my rails app to a warehouse that fulfills orders places in my store. The warehouse has a format for the CSV, and ironically the header line of the CSV file is super long (1000+ characters).

我在一个换行符csv文件的标题行,当我收到测试的电子邮件,无法弄清楚什么放在那里。但是,一些googling终于显示了原因:附加文件的行字符限制为1000.为什么?我不知道。

I was getting a line break in the header line of the csv file when I received the test emails and couldn't figure out what put it there. However, some googling has finally showed the reason: attached files have a line character limit of 1000. Why? I don't know. It seems ridiculous, but I still have to send this csv file somehow.

我尝试手动将附件的MIME类型设置为text / csv,但这是没有帮助的。有人知道如何解决这个问题吗?

I tried manually setting the MIME type of the attachment to text/csv, but that was no help. Does anybody know how to solve this problem?

一些相关的google结果: http://www.google.com/search?client=safari&rls=en&q=csv+wrapped + 990& ie = UTF-8& oe = UTF-8

Some relevant google results : http://www.google.com/search?client=safari&rls=en&q=csv+wrapped+990&ie=UTF-8&oe=UTF-8

更新

我已经尝试编码base64中的附件,如下:

I've tried encoding the attachment in base64 like so:

    attachments['205.csv'] = {:data=> ActiveSupport::Base64.encode64(@string), :encoding => 'base64', :mime_type => 'text/csv'}

这似乎没有起到什么作用。我通过Sparrow for Mac收到包含me.com帐户的电子邮件。我会尝试使用gmail的网络界面。

That doesn't seem to have made a difference. I'm receiving the email with a me.com account via Sparrow for Mac. I'll try using gmail's web interface.

推荐答案

这似乎是因为SendGrid邮件服务器正在修改附件内容。如果您发送带有纯文本存储MIME类型的附件(例如 text / csv ),则会按照您观察到的内容每990个字符包裹一次。我认为这与 RFC 2045/821 有关:

This seems to be because the SendGrid mail server is modifying the attachment content. If you send an attachment with a plain text storage mime type (e.g text/csv) it will wrap the content every 990 characters, as you observed. I think this is related to RFC 2045/821:



  1. 内容传输编码标题字段

  1. Content-Transfer-Encoding Header Field

可以通过电子邮件有用地传输的媒体类型是以自然格式表示的
,作为8位字符或二进制

数据。

例如,RFC 821(SMTP)将邮件消息限制为7位US-ASCII

数据,行数不超过1000个字符,包括任何
CRLF行分隔符。

Many media types which could be usefully transported via email are represented, in their "natural" format, as 8bit character or binary
data. Such data cannot be transmitted over some transfer protocols.
For example, RFC 821 (SMTP) restricts mail messages to 7bit US-ASCII
data with lines no longer than 1000 characters including any trailing CRLF line separator.

因此,有必要为

定义标准机制,将这样的数据编码为7位短行格式。正确标记

未限制格式的未编码材料,以便直接使用超过
的限制性传输也是可取的。此文档

指定此类编码将由新的Content-

Transfer-Encoding头字段指示。此栏位尚未由

任何先前的标准定义。

It is necessary, therefore, to define a standard mechanism for
encoding such data into a 7bit short line format. Proper labelling
of unencoded material in less restrictive formats for direct use over less restrictive transports is also desireable. This document
specifies that such encodings will be indicated by a new "Content-
Transfer-Encoding" header field. This field has not been defined by
any previous standard.


如果您使用base64编码(而不是默认的7位元)传送附件,附件会保持不变(没有加入换行符):

If you send the attachment using base64 encoding instead of the default 7-bit the attachment remains unchanged (no added line breaks):

attachments['file.csv']= { :data=> ActiveSupport::Base64.encode64(@string), :encoding => 'base64' }

这篇关于如何发送长度超过990个字符的csv附件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆