There may be times when you wish to send an email or SMS text message from your application but ran across any of the following obstacles:
- You don't have access to an SMTP server or SMS gateway
- You can't setup your own SMTP server or SMS gateway
- Your own SMTP server or SMS gateway is blocked by your Internet Service Provider (ISP) or your organization's firewall
- You don't have authorization to send external emails (emails can only be sent to addresses within the organization), etc.
There are several workarounds to such problems, which this article presents. You may or may not have heard of some of the workarounds. For the sake of brevity, this article only describes how the workarounds work. Generally, no source code or executable demos of the workarounds are given but links are included to articles that have the relevant source code or executable demos.
The article is divided into workarounds for sending emails and sending SMS text messages.
SMTP Email Workarounds
SMS Text Messaging Workarounds
SMTP Email Workarounds
Use SMTP Authorization/Authentication
You may or may not know this, but when you connect to an SMTP server, you can provide login credentials (e.g. username and password) to authorize/authenticate yourself with the server. This allows you to send emails anywhere. This is how email clients work for retrieving POP3 or IMAP email and sending email via SMTP. However, standalone SMTP tools for application development or command line usage, etc. generally do not provide examples on using authorization when connecting to an SMTP server. Additionally, half or more of these tools do not include an option to provide the login credentials for authorization, which means it is likely that you can only send emails within your organization, etc. (no external emails). The tools just assume you don't need authorization.
NOTE: Using SMTP authorization may jeopardize your email account since some tools use/require the login credentials as unencrypted plain text. Examples include the need to supply the account information on the command line or in a text configuration file. So use with caution.
How to Implement SMTP Authentication/Authorization
Since there are numerous SMTP utilities out there some of which do support SMTP authorization, this article does not provide any such tools. But some links are provided for reference. In building your application, follow the SMTP protocol (or its RFC specification) including the option for SMTP authentication/authorization, or use an SMTP library that has such support. If using .NET, the library has everything, you just need to implement it into your application (see reference links, particularly the first link).
Example of How to Use SMTP Authentication/Authorization
You can use Blat on Windows or something like msmtp on Unix/Linux platforms. The example here is for Blat and only shows one use case. There are more options you can specify.
Blat -to email@example.com -subject "theSubject" -body "theMessage"
-server SMTPServer@addr.com -u YourUsername -pw YourPassword
Use DNS MX (Mail) Server Lookup
You can perform DNS MX (mail) server lookups of the mail servers for the domains of the email addresses you wish to send to. Then you can directly connect to those SMTP servers to send the email. Since the destination is within those server's domain/organization, no authentication is necessary. There may be some security and ethical issues with this approach and you may still be blocked from sending emails some of the time, but this is one alternative workaround.
How to Implement DNS MX Lookup + SMTP to Send Emails
There are not many tools that use this approach. I have included a Windows command line tool (with source code for Visual C++ 7.0) that uses this approach and is based on the code of the first link in the following references. This tool requires Window 2000 or above, and can only send 1 email at a time. The tool also will not likely support Unicode as I did not properly code the tool, though it should work fine for English in ASCII format. The code is simply a Windows console or command line executable wrapper to the main code snippet presented in the reference article mentioned. For details on the code of this tool, please download and look at the source as well as the reference article link. It would be nice if someone implemented a COM/ActiveX DLL wrapper to that code (I'm not familiar with building COM applications myself).
Example of How to Use DNS MX Lookup + SMTP to Send Emails
The example is based on the tool I built. The executable is located under the Bin/Release directory of the Visual C++ 7.0 project that you can download from this article. The example only shows one use case. There are more options you can specify.
mxmail "fromName" firstname.lastname@example.org email@example.com "subject" -t
SMS Text Messaging Workarounds
Use SMTP and Mobile/Cell Phone Carrier's SMS Gateway
You can send SMS text messages as short email messages (long messages may be truncated). To do so, you send a normal short email message via SMTP but send to an address with the following pattern: phoneNumber@carrierDomain.com like firstname.lastname@example.org. This may require the SMTP email workarounds also since you are likely sending to an external email address. This method is easy to do but requires knowing the carrier SMS gateway email address format. You can find these in some of the URL references that follow, or by searching for something like "carrier SMS gateways".
How to Implement SMS via Carrier Gateway Addressing
Use an SMTP library or tool to send the SMS text message via email (see SMTP workarounds in this article). But you must first do a carrier to gateway email address translation - this should be easy to do. To get some translation mappings, search the web or try the reference links that follow.
Example of How to Use SMS via Carrier Gateway Addressing
The example is based on the tool I built. The executable is located under the Bin/Release directory of the Visual C++ 7.0 project that you can download from this article. The example only shows one use case. The example assumes you have the translation already done.
mxmail "fromName" email@example.com firstname.lastname@example.org "subject" -t
Use a "Send SMS Text Message" Web Form
There are numerous websites out there that allow you to send SMS text messages. They do the hard work for you. You just fill in the form and click send, etc. You don't need to know the carrier's SMS gateway email address format. You just need to know the destination phone number and maybe the carrier of that phone number. Some of these services are free, some of them are not. Some work well, some don't.
To make better use of these web forms, you can hack them in the following ways: have your application forward the data to the web form or have your application submit the data directly to the form's processing script (bypassing the form itself, using your own form, etc.). Using the latter approach, you can make HTTP POST requests to the form processing script.
How to Implement SMS via SMS Web Form Hack
How you implement this depends on your preference and skills. Two techniques are given in the references that follow.
Example of How to Use SMS via SMS Web Form Hack
If you use the Perl automation method in the reference article link to record your form submission into a script, you can then edit the script to accept command line parameters, etc. for you to specify the recipients and message later on when you use the script.
- 11/04/06 - Initial post
- 11/24/06 - Added information for beginners on how to implement or use some of the ideas presented in the article