添加空白字符后,C ++电子邮件就会中断

时间:2019-02-23 00:18:41

标签: c++ libcurl

因此,基本上我想做的是发送包含多个变量的消息。如果条件匹配,变量将显示为消息。否则,它将为空白。我为此使用libcurl,这是当前的电子邮件消息:

char chartest[] = "This is Message #1";
char chartest2[] = "This is Message #2";
char chartest3[] = "This is Message #3";
const char *payload_text[] = {
    "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n",
    "To: " TO "\r\n",
    "From: " FROM "\r\n",
    "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
    "rfcpedant>\r\n",
    "Subject: Test!\r\n",
    "\r\n",
    "Testing.\r\n",
    chartest, "\r\n",
    chartest2, "\r\n",
    chartest3, "\r\n",
    NULL
};

这将显示:

Testing.
This is Message #1
This is Message #2
This is Message #3

这就是我想要的。

但是,如果我将其中一条消息设置为空白(因为我不希望用户收到此消息):

char chartest[] = "This is Message #1";
char chartest2[] = "";
char chartest3[] = "This is Message #3";
const char *payload_text[] = {
    "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n",
    "To: " TO "\r\n",
    "From: " FROM "\r\n",
    "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
    "rfcpedant>\r\n",
    "Subject: Test!\r\n",
    "\r\n",
    "Testing.\r\n",
    chartest, "\r\n",
    chartest2, "\r\n",
    chartest3, "\r\n",
    NULL
};

它将显示:

Testing.
This is Message #1

由于某些原因,它会跳过Message #3

如何实现此功能以跳过某些消息或其他文本,而不完全跳过其余消息?

编辑:

这是我正在使用的示例。除了消息(和添加的char值)外,代码是相同的。

https://github.com/curl/curl/blob/master/docs/examples/smtp-tls.c

我还稍微修改了代码。

char chartest[] = "This is Message #1";
char chartest2[] = "This is Message #2";
char chartest3[] = "This is Message #3";
const char *payload_text[] = {
    "Date: Mon, 29 Nov 2010 21:54:29 +1100\r\n",
    "To: " TO "\r\n",
    "From: " FROM "\r\n",
    "Message-ID: <dcd7cb36-11db-487a-9f3a-e652a9458efd@"
    "rfcpedant>\r\n",
    "Subject: Test!\r\n",
    "\r\n",
    "Testing.", chartest, chartest2, chartest3, "\r\n",
    NULL
};

不幸的是,这仍然是一个问题。

编辑2:

我想知道是否chartest2被视为“ NULL”,从而在实际NULL之前过早结束了消息。如果是这样,那么我想知道如何设置空白(但不能为null)char。

0 个答案:

没有答案