Why Use SMTP?


Writing directly to an SMTP service is not your only option in developing an email-capable program. Mail APIs exist which have many capabilities not found in SMTP. Alternatively, you could write your own API layer over SMTP. So why you would want to use the SMTP service directly?

The first question to be resolved is: would you rather use an existing API or write your own? The only justification for writing your own is that you would be fundamentally improving the system. SMTP is what most of the current mail APIs use to deliver mail and it is very easy to communicate with. However, sending messages with attachments, especially binary files, can get pretty messy with the SMTP. Don't reinvent the wheel. If your code is already using another API such as Microsoft's MAPI, then just use it instead of bothering to adapt to a format that may not reap significant benefits. Another reason that you might not want to use SMTP directly is that sent messages are tracked automatically through systems such as MAPI, but messages sent directly to the SMTP service are never even seen by MAPI.

Benefits of SMTP

There are reasons why you would want to talk to the SMTP service. You may want to use SMTP directly if you don't have any mail APIs easily accessible. This might be the case if you are developing for either MS-DOS or Unix. Another reason would be that you are trying to develop an application with very little overhead. For example, you might be developing an ATL, COM, or DCOM application.

A Case in Point

The reason I recently decided to go with SMTP directly was portability. I started investigating SMTP when I was developing an NT service application. Although I could use MAPI, or any other messaging API, I needed mail for just one small part of my application. I needed to send email to one address when the service was being stopped, with a message indicating why it was stopping. This service delivers software updates and patches to our customers via FTP. If this service stops running for any reason, our 24x7 customers won't get their updates. We needed to know right away when this occured. I must admit that the easy way would have been to just use an existing API and get on with the important coding. However, I felt it likely we would have to port this to our Unix systems, which don't have MAPI. This warranted further consideration for SMTP. I investigated further about what's involved in communicating with SMTP. I found out that it's actually easier to send a basic text message directly to SMTP than it is to use any of the APIs I had previously investigated. That swayed my decision in favor of writing directly to SMTP.