如何使用C ++发送电子邮件(curl)

时间:2018-06-26 13:25:27

标签: c++ email curl send

如何在此电子邮件中添加主题?

    #include <windows.h>

int main(void){
    char* command = "curl smtp://smtp.gmail.com:587 -v --mail-from \"SENDER.EMAIL@gmail.com\" --mail-rcpt \"RECEIVER.EMAIL@gmail.com\" --ssl -u SENDER.EMAIL@gmail.com:PASSWORD -T \"ATTACHMENT.FILE\" -k --anyauth";
    WinExec(command, SW_HIDE);
    return 0;
}

1 个答案:

答案 0 :(得分:1)

有两种发送主题为 cURL 的邮件的方法:命令行和From C ++代码。

命令行:

可以在电子邮件数据文本文件“ email.txt”中指定主题

curl smtp://mail.example.com --mail-from myself@example.com --mail-rcpt
receiver@example.com --upload-file email.txt

以下是教程:cURL_SMTP_Command_Line

来自C ++代码:

在这种情况下,您在有效负载文本中指定“主题”。

  static const char *payload_text[] = {
  "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n",
  "To: " TO_MAIL "\r\n",
  "From: " FROM_MAIL "\r\n",
  "Cc: " CC_MAIL "\r\n",
  "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
  "rfcpedant.example.org>\r\n",
  "Subject: SMTP example message\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",
  NULL
};

这里是示例:cURL_SMTP_From_Code