3

我正在使用 curl 库发送电子邮件。我能够成功发送电子邮件。我可以在接收端正确地看到 FROM、主题和正文。现在我需要在电子邮件中添加附件。我以这种方式遵循:http: //msdn.microsoft.com/en-us/library/ms526560 (v=exchg.10).aspx

static const char *text[]={
  "Date: Wed, 06 Feb 2013 12:30:30 +1100\n",
  "To: " RECIPIENT "\n",
  "From: " MAILFROM "\n",
  "MIME-Version: 1.0",
  "Content-Type: multipart/mixed",
  "boundary=""XXXXX""\n",
  "Subject: email example message\n",
  "--XXXXX",
  "\n", /* empty line to divide headers from body, see RFC5322 */
  "The body of the message starts here.\n",
  "Check RFC5322.\n",
  "--XXXXX",
  "Content-Type: text/plain" "\n",
  "Content-Disposition: attachment" "\n",
  "filename="FILE_PATH "\n",    
  "--XXXXX--",
  NULL
};

他们建议使用 RFC5322。但在那我找不到任何类似依恋的东西。这是对的吗?也欢迎使用 libcurl + C 语言的任何其他方式。

我认为名叫 Jorge 的人在 2012 年 10 月 13 日提出了同样的问题。但答案并不存在。

4

4 回答 4

2

最简单的方法是使用 base64 编码之类的东西进行编码,它将二进制数据转换为能够通过电子邮件发送的 ASCII 字符。base64 对文件进行编码并插入字符串,如下所示。用正确的东西替换大写字母中的所有内容。

--XXXXboundary text
Content-Type: application/FILETYPE; name="FILENAME"
Content-Disposition: attachment; filename="FILENAME"
Content-Transfer-Encoding: base64
STRINGFROMBASE64ENCODING

这是关于 base64 的一个线程:如何在 C 中进行 base64 编码(解码)?

于 2013-02-26T05:22:44.200 回答
0

我认为你是对的,但你为什么附加一个空文件?我认为你需要在最后的附件身体公寓里放一些东西。

例如:

--XXXXboundary text 
Content-Type: text/plain;
Content-Disposition: attachment;
        filename="test.txt"

this is the attachment text ---- this is attachment content

--XXXXboundary text--
于 2013-02-06T10:51:21.097 回答
0

也许你应该看看 libquickmail ( http://sf.net/p/libquickmail/ )。它完成了附加文件所需的所有魔法,它使用 libcurl 进行 SMTP 传输(甚至在 libquickmaillight 中没有 libcurl)。

于 2013-02-18T22:33:28.253 回答
0

可以按如下方式完成;

static const char *payload_text[] = {
  "To: " TO "\r\n",
  "From: " FROM "(Example User)\r\n",
  "Cc: " CC "(Another example User)\r\n",
  "Subject: SMTPS Example\r\n",
  "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n",
  "User-Agent: My eMail Client\r\n",
  "MIME-Version: 1.0\r\n",
  "Content-Type: multipart/mixed;\r\n",
   " boundary=\"------------030203080101020302070708\"\r\n",    
  "\r\nThis is a multi-part message in MIME format.\r\n",
  "--------------030203080101020302070708\r\n",
  "Content-Type: text/plain; charset=utf-8; format=flowed\r\n",
  "Content-Transfer-Encoding: 7bit\r\n",
  "\r\n", /* empty line to divide headers from body, see RFC5322 */
  "The body of the message starts here.\r\n",
  "\r\n",
  "It could be a lot of lines, could be MIME encoded, whatever.\r\n",
  "Check RFC5322.\r\n\r\n",
  "--------------030203080101020302070708\r\n",
  "Content-Type: text/plain; charset=utf-8; format=flowed\r\n",
  "  name=\"send.c\"\r\n",
  "Content-Type: text/plain; charset=utf-8; format=flowed\r\n",
  "Content-Disposition: attachment;\r\n",
  "  filename=\"abc.txt\"\r\n",
  "\r\n",
  "bla bla file content is here\r\n",
  "--------------030203080101020302070708--\r\n",
  NULL
};
于 2015-11-06T12:58:40.943 回答