Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.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
如何使用libcurl和c语言通过电子邮件发送附件?_C_Linux_Libcurl - Fatal编程技术网

如何使用libcurl和c语言通过电子邮件发送附件?

如何使用libcurl和c语言通过电子邮件发送附件?,c,linux,libcurl,C,Linux,Libcurl,我正在使用curl库发送电子邮件。 我能够成功地发送电子邮件。在接收端,我能正确地看到物体、主体和身体。 现在我需要的是在电子邮件附件。 我是这样做的: 他们建议使用RFC5322。但在这一点上,我找不到像依恋这样的东西。 对吗?也欢迎使用libcurl+C语言的任何其他方式 我想那个叫豪尔赫的人在2012年10月13日也问过同样的问题。但是答案不在那里。我认为你是对的,但是你为什么附加了一个空文件?我想你需要在最后的附体公寓里放些东西 例如: --XXXXboundary text Con

我正在使用curl库发送电子邮件。 我能够成功地发送电子邮件。在接收端,我能正确地看到物体、主体和身体。 现在我需要的是在电子邮件附件。 我是这样做的:

他们建议使用RFC5322。但在这一点上,我找不到像依恋这样的东西。 对吗?也欢迎使用libcurl+C语言的任何其他方式


我想那个叫豪尔赫的人在2012年10月13日也问过同样的问题。但是答案不在那里。

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

例如:

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

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

--XXXXboundary text--

也许你应该看看libquickmail()。
它完成了附加文件所需的所有功能,并使用libcurl进行SMTP传输(甚至在libquickmailllight中不使用libcurl)。

最简单的方法是使用base64编码之类的东西进行编码,它将二进制数据转换为可以通过电子邮件发送的ASCII字符。base64编码文件并插入字符串,如下所示。用正确的材料替换瓶盖中的所有东西

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

base64上有一个线程:

可以按如下方式执行

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
};

电子邮件的标准分隔行是
“\r\n”
@pmg,请您解释一下。@Malay:您在RFC中指出:“一行是一系列字符,由回车符和换行符两个字符分隔”;我想我必须给出文件所在的路径,它将从那里获取文件。根据您的建议,它正在打印电子邮件中的“这是附件文本”。我请求关闭此帖子。谢谢。我会检查自己能做些什么。如果我能做到这一点,我会发布答案。
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
};