curl / Mailing Lists / curl-library / Single Mail
Buy commercial curl support from WolfSSL. We help you work out your issues, debug your libcurl applications, use the API, port to new platforms, add new features and more. With a team lead by the curl founder himself.

SMTP without HTML or CRLF into inline_html

From: Ed Hardin via curl-library <>
Date: Mon, 02 Jan 2023 14:11:57 -0600

Using C++, Windows 10, console app, Visual Studio 2019

All of the libcurl examples that I see have inline_html[] as hard coded like

static const char inline_html[] =
  "<p>This is the inline <b>HTML</b> message of the email.</p>"
  "<br />\r\n"
  "<p>It could be a lot of HTML data that would be displayed by "
  "email viewers able to handle HTML.</p>"

I'm passing parameters to the main function for To, From, CC, Subject, and Body and want to build the inline_html[] programmatically from the Body. I retrieve my Body parameter like this

std::string strBody = argv[5];

The problem that I am running into is converting the CRLFs in the string strBody into CRLFs in the const char inline_html[] that are acutal CR and LFs.

If I build a string for the HTML like this

std::string strNewHTML = "<html><body><p>\r\n";
strNewHTML += "<br /> \r\n";
strNewHTML += strBody;
strNewHTML += "</p></body></html>\r\n";

and convert that to const char like this

char* inline_html = new char[strNewHTML.length() + 1];
inline_html[strNewHTML.length()] = '\0';
for (int i = 0; i < strNewHTML.length(); i++) {
  inline_html[i] = strNewHTML[i];

I get the Body of the email that is sent without CRLF. Just a runon block of text.

If, instead, I first replace the hex 0x0A in the strBody with "\n" I just get the text "\n". If I replace it with an escape sequence I just get the text "\\n". Same with 0x0D replacing with \r or \\r.

So what I need is to either find a way to put the CRLF into the inline_html[] programmatically or to create an email that is text only which would be fine since the email I intend to send really does not have any formatting.

All the examples seem to always have the multipart for text and html. I've been commenting out what seem to be the lines indicating html but I end up with a blank email. Is there an example that I am missing for a straight text email.

My current code looks very much like What would I need to comment out or change to make this text only?

I'm sure it is simple but I seem to just be going around in circles.


This email has been checked for viruses by AVG antivirus software.

Received on 2023-01-02