In my project I use libgmime for MIME types. I am trying to create a new GMimeMessage by using std :: string as a body. According to Docs, this data can be made using GMimeStream and GMimeDataWrapper , and then MIME to GMimePart with this data The new message can be set as part. Code:
std :: string body = "some test data"; GMimeMessage * message = g_mime_message_new (FALSE); // set header g_mime_object_set_header ((GMimeObject *) message, name.c_str ()), value.c_str (); // Create the stream and write the data in it. GMimeStream * Stream; G_mime_stream_construct (stream, 0, body.length ()); G_mime_stream_write_string (stream, body.c_str ()); GMimeDataWrapper * wrapper = g_mime_data_wrapper_new_with_stream (stream, GMIME_CONTENT_ENCODING_DEFAULT); // GMimePart to set GMimeMessage as the mime part of GMimePart * mime_part = g_mime_part_new (); G_mime_part_set_content_object (mime_part, wrapper); G_mime_message_set_mime_part (Message, (GMimeObject *) mime_part);
When I try to create a message like this, I get a segment here:
g_mime_stream_write_string (stream, body.c_str () );
Maybe I'm using the wrong method of messaging ... can this be done correctly?
You have bad initialization GMimeStream * stream
. Requirement:
GMimeStream * stream; / * Start GMIM * / g_mem_init (0); Create a stream around / * Stdout * / stream = g_mime_stream_mem_new_with_buffer (body_part.c_str (), body_part.length ());
View document: and sample:
No comments:
Post a Comment