0

I am successfully sending a mime message using libcurl. However, in the received email I can only see the "username" in the From: field.

    curlCode_ = curl_easy_setopt(curl, CURLOPT_MAIL_FROM,    from_field);
    recipients = curl_slist_append(recipients, (const char *)to_);
    recipients = curl_slist_append(recipients, cc.str().c_str());
    curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);

I assume its a security feature at gmail, ensuring that the sender is always shown in the From field. Another issues is that I send out a multi-part mime message with an alt text portion. In zoho mail, I can view the HTML, however gmail always shows the text part.

For reference, I make sure the HTML comes before the text.

    /* Build the mime message. */
    mime = curl_mime_init(curl);

    /* The inline part is an alternative proposing the html and the text
       versions of the e-mail. */
    alt = curl_mime_init(curl);

    /* HTML message. */
    part = curl_mime_addpart(alt);
    curl_mime_data(part, html_body_.c_str(), CURL_ZERO_TERMINATED);
    curl_mime_type(part, "text/html");

    /* Text message. */
    part = curl_mime_addpart(alt);
    curl_mime_data(part, body_.c_str(), CURL_ZERO_TERMINATED);

    /* Create the inline part. */
    part = curl_mime_addpart(mime);
    curl_mime_subparts(part, alt);
    curl_mime_type(part, "multipart/alternative");
    slist = curl_slist_append(NULL, "Content-Disposition: inline");
    curl_mime_headers(part, slist, 1);

The code is rather long and in multiple classes, so I can post any code deemed relevant to avoid clutter. Essentially I am unsure how to debug this.

moi
  • 467
  • 4
  • 19
  • For reference, I make sure the HTML comes before the text. – moi Apr 23 '21 at 18:27
  • 1
    @TedLyngmo I changed it to C. – moi Apr 23 '21 at 18:29
  • As a reference, similar problems involving gmail. https://stackoverflow.com/questions/21897180/gmail-does-not-render-html-in-email https://www.gitmemory.com/issue/curl/curl/5748/666491251 – moi Apr 23 '21 at 20:27
  • I cannot mark my answer - stackexchange does not like me enough. So perhaps someone else can mark this --> The text part has to be before the html part. Now both zohomail and gmail display the html. – moi Apr 24 '21 at 08:52

1 Answers1

0

The specific problem - The text part of a multi-format MIME has to be before the html part. Now both zohomail and gmail display the html.

A more general answer relating to libcurl debugging - I use the curl program instead. Use -libcurl option to generate C code that can be used in your C/C++ project. There are sample curl commands available with most REST APIs.

moi
  • 467
  • 4
  • 19