WRITEMIME: C++ code to create MIME messages

email address: jean-francois.dockes@wanadoo.fr


Package home page: http://perso.wanadoo.fr/dockes/writemime/

The detailed documentation is not included with the package, because it is much bigger than the code, thanks to doxygen... You will find it at the home page. Reading the present file, the exemple uses in wmmain.cpp, and maybe the comments in writemime.h is probably enough for simple needs.

You will find a very nice set of MIME RFCs at: http://www.nacs.uci.edu/indiv/ehood/MIME/MIME.html


I needed a programmatic way to create E-mail messages with attachments, and I could not find any simple package with this functionality.

Under Unix, executing an external mailer was not an option, because there is no uniform mailer interface.

Extracting code from a program like pine or mutt would have been a possibility but they are not structured to let you do this easily, or are covered by the GPL.

Being totally incompetent about MIME email and very slightly less so about C++ programming, I proceeded to write a (very basic) C++ MIME package.

Note that, by default, writemime uses sendmail to actually send the formatted message. Other MTAs would surely work too. But this probably means that the module is not very useful under Windows, unless you have another way to speak SMTP.

Writemime is free and covered by a BSD-like license, and you are free to use the code as you wish.


Writemime will let you create two kinds of MIME messages:

Creating a message is trivially easy, and writemime will handle all encoding issues internally.

Sample code to create and send a message:

#include "writemime.h"

using namespace WriteMime;

void myCreateMessageWithNoErrorHandling()
  CompositeMessage msg(Entity::MULTIPART, "mixed");
  msg.setSubject("Mime multipart test message");
  msg.addRecipient("me@myisp.com", "My R. Name");

  DiscreteEntity txt, attach;

  const char *body = "This is the message body text\nSecond line\r\n";
  txt.setBody(body, strlen(body), Entity::TEXT);

  attach.setBodyAttach("/usr/bin/yes", Entity::APPLICATION, "octet-stream");

There is also a driver program (writemime) which will let you access most of the functionality from the unix command line. Type 'writemime -h' after compiling the package to get a hopefully helpful usage message.

The driver provides a somewhat degraded way to access writemime functionality from a non-c++ program, or interactively..


There is no installation procedure. Have a look at the Makefile, and compile the driver if you wish to use it. Else, just incorporate writemime.c++ and writemime.h in your program.

Things missing

The following features are not currently supported, because I had no need for them, but I have no doubt that the module could be improved relatively easily if the need arises:

As far as I know the messages that the package creates are conformant to the RFCs, but the code is young and could be buggy.

Generated on Fri Feb 6 11:53:40 2009 for WriteMIME by  doxygen