NOTICE: this web page will rest online but will no longer be updated.
To get the updated web page click here:
ESMTP/SMTP client
Writing a SMTP client from scratch:
how to send an e-mail and an attached binary file
Objective of this article is to write some C++ code to send an e-mail, togheter with its
binary attachment, without buying any component on the web.
Prerequisite is being in posses of the DLL described in Build your
own ASPI dll. You are certainly asking: what does ASPI have to do with the SMTP client?
Nothing. But I just needed some place to put into several win32asm functions that encode
Base64 the binary attachment, and I developed and added these functions into the ASPIDLL.DLL
for the sake of simplicity.
The DLL is freeware from this site, and comes complete with full source code. You can also
download it already assembled and zipped, in case you are not familiar with MASM32.
SMTP stands for Simple Mail Transfer Protocol, and is a very simple protocol
used to send mail messages from a sender to a recipient. It is one of the first
and most used Internet protocols, released in 1982 and described in RFC 821.
Mail messages, in turn, are messages sent over the Internet according to the SMTP
client/server model outlined below. These messages must be formatted according to RFC 822
(Standard for ARPA Internet Text Messages). This makes it evident that mail messages
are pure text messages, nothing but normal, plain, character messages.
Additional note: ESMTP stands for Extended SMTP, and is a successive implementation of SMTP that
is described in some RFCs that you can find on the web. Essentially ESMTP adds some features
to the SMTP (without altering it) and uses some forms of authentication mechanisms to identify
the mail sender and thus reducing the possibility of spamming (see RFC 2554).
SMTP servers are servers that operate according to RFC 821. SMTP clients
are clients that operate according to RFC 821 too.
Original SMTP did not define any provision for attachments, and for binary attachments less
than ever, but some elegant *tricks* have been invented since 1982 to accomodate this
indispensable feature. Please note that the original SMTP protocol is still used even
when attachments are sent, and the protocol itself remains unaltered.
These "tricks" are named MIME and Base64 encoding, and are described into
the following paragraphs.
|