John Ratcliff's Code Suppository

A place where I insert my code into the anus of the Internet.

 

Monday, June 23, 2008

SendMail : Send mail using embedded Blat



I am uploading today a code snippet of somewhat questionable value. This is a true snippet, in that it is composed of a single .CPP and .H file. In a simple one line API call you can send an email from your code. You can download the source, project, and executable using this link SendMail.zip

My specific use case for this is that I need to be able to get notifications from a remote server when it is in a bad state. What I really want to do is just send an instant message. However, after searching the Internet, I realized that it was going to be extremely difficult to find a true code snippet which could do such a thing. Theoretically Jabber would allow me to do this, but all of the source code libraries for Jabber are simply massive and include insane amounts of graphics/UI code. Even the one or two console versions of Jabber are still overwhelming.

If anyone knows of an implementation of an instant messaging API that allows me to simple use the form of send message 'from' this person 'to' this person with 'this subject' and 'this text', that would be awesome.

In the meantime I have resorted to sending emails. Blat is a simply awesome full public domain console email program. You can use it either as a console executable or as a DLL.

What I have done is created a single CPP file that not only provides a simple wrapper routine to send an email but also contains, embedded within it, the Blat DLL. Simply add this one CPP and header file to your project and you can transmit an email message in your program.

The DLL is loaded directly from memory, not from a file on disk, using the routing MemoryModule written by Joachim Bauch. See his full article here.

Like I said, this may be of questionable value but if you are looking for a completely turnkey way of just sending an email from inside your program this will do it. You could always just add the blat source code to your project, which is an entirely viable option, but there is a lot of source in Blat and this form might be easier to use.

The file 'SendMail.h' provides two methods. The first is as follows:

bool sendMail(const char *mail_server, // mail server to use for sending the email message.
const char *from, // email address of the sender
const char *to, // email address to send to.
const char *subject, // the subject line of the email.
const char *body, // the body text of the email.
const char *attachment); // an optional attachment file.

The second option is to just invoke the Blat dll function directly. In which case you will need to familiarize yourself with the full Blat command line interface which has a lot of options.

bool sendBlat(int argc,const char *argv[]); // refer to the Blat documentation for the full set of command line arguments.

Another cool way to use this program is to send SMS text messages to your mobile phone.

Sending SMS through email is very, very easy. If you can be reminded through email, you can now be reminded through SMS.

If you know the correct email address, you can also send these messages to your cellular phone. Here are the email addresses for the 6 most popular cellular phone carriers:

T-Mobile:phonenumber@tmomail.net
Virgin Mobile:phonenumber@vmobl.com
Cingular:phonenumber@cingularme.com
Sprint:phonenumber@messaging.sprintpcs.com
Verizon: phonenumber@vtext.com
Nextel: phonenumber@messaging.nextel.com

where phonenumber = your 10 digit phone number

1 Comments:

  • At 11:31 AM, Blogger polyvertex said…

    As for making a very light Jabber "client", you can check the gloox library which is written in clean C++ and well maintained (the "samples" directory in the archive is may be what you are searching for).

    Cheers.

     

Post a Comment

<< Home