cURL / Mailing Lists / curl-library / Single Mail


RE: Why syntax error in release version of code in visual c++

From: Steve Holme <>
Date: Wed, 5 Feb 2014 23:11:37 +0000

On Wed, 5 Feb 2014, ansh kumar wrote:

> * Connection #0 to host left intact
> > QUIT
> < 221 2.0.0 closing connection iu7sm77803912pbc.45 - gsmtp
> * Closing connection #0
> Is it some kind of error or what?

From what I remember of the pre-multi work of January 2013 yes that looks

In SMTP terms a QUIT is always sent to terminate the connection. However,
because the easy interface now uses the multi-interface underneath you don't
currently see that QUIT with curl 7.29 and above :(

> And my code is in the attachment.
> strcpy(fileBuf[len++],"To: " TO "\r\n");
> buffer_size += strlen(fileBuf[len-1]) + 1; // 1 for \0

Why are you adding one for the null to the buffer_size, which you then pass
to curl as the INFILESIZE?? That doesn't seem right to me and looks like you
are telling curl to tell the email server the incorrect size of the email -
admittedly by only a few bytes but still the wrong size.

As you are using STL elsewhere in your code, I would recommend using a
std::string for the payload along with a character count rather than an
array of fixed length lines with a line counter. For example:

struct fileBuf_upload_status
  std::string payload;
  size_t counter;

Then in your fileBuf_source() function you can do something like:

static size_t fileBuf_source(void *ptr, size_t size, size_t nmemb, void
    struct fileBuf_upload_status *upload_ctx = (struct fileBuf_upload_status

    size_t len = std::min(payload.length() - upload_ctx->counter, size *
    if(len > 0)
        memcpy(ptr, upload_ctx->payload.c_str() + upload_ctx->counter, len);
        upload_ctx->counter += len;

    return len;

That way you a) don't have to let curl call your callback so many times, but
instead can fill the buffer up as much as possible - for example up to 16k,
b) don't have to have a blank line to signify the end of the data c) have
fixed row length lines of 200 characters and d) don't have to dynamically
allocate your fileBuf - just let STL do the work for you ;-) In that respect
the examples are written as simple examples without any other libraries such
as STL in mind.

Saying that... email clients tend to limit the length of each line to 78
characters including the \r\n - just take a look at your email with POP3 and
you'll see that headers span multiple rows because of this and base64 and
quoted printable encoded attachments and inline images will be wrapped at 76
characters ;-)

Kind Regards


List admin:
Received on 2014-02-06