Class CMailSMTP

The JavaScript variant of the  FPE supports a simplistic printer spooler using a node SMTP package to attach a file to an email and send it to HPs ePrint service for printing  on a local HP printer. As a exercise it was decided to add this functionality to the C++ variant of the FPE and in order to provide this some way of creating an email, attach a file and sending it was needed.

Several high level C/C++ libraries exist to perform this functionality but it was decided to write as much of the SMTP protocol handling code as possible and so it was decided to use libcurl which is suitably low level that a significant part of the protocol handling had to be written. Another reason for using is that it is written in highly portable C and available on most platforms/operating systems and it supports most internet based protocols so useful in a wide variety of future projects.

From this was born the class CMailSMTP which enables the caller to set email server URL/ account details,  any recipients for the email, attach mutiple files encoded in either 7bit or base64 and then send the email. The class uses libcurl to connect to the server including login, setting up an SSL connection)and perform the actual email transfer but constructing the contents of the email including headers and encoded data are performed by the class itself.

The class itself only dependencies at present are C11+,  libcurl and some Linux specific code that reads file /etc/mime.types to setup a table for file extension to MIME type mapping ( changing this to be more portable is penciled in to be looked at in future).

.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s