Click here to Skip to main content
12,818,688 members (28,635 online)
Click here to Skip to main content
Add your own
alternative version


120 bookmarked
Posted 4 Nov 2006

Some Easy Ways to Send Emails (via SMTP) and SMS Text Messages

, 30 Dec 2007 CPOL
Rate this:
Please Sign up or sign in to vote.
A beginner's guide on how to send emails (via SMTP) and SMS text messages when you don't have adequate access to the necessary resources


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 -subject "theSubject" -body "theMessage" 

-server -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" "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: like 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" "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.

NOTE: Use of such hacks may be in violation of the service's terms of use. And the services may alter the service, which would require updating your code.

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


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Software Developer
United States United States
Practitioner of C#, .NET, C++, C, ASP, VBScript, Windows Scripting Host, JScript, Perl, Perlscript, ADO.

Interested in automation, systems & application integration, web services & applications, and mobile computing.

You may also be interested in...

Comments and Discussions

GeneralGood program but limited use for paths ... Pin
Rob Kell6-Oct-10 10:27
memberRob Kell6-Oct-10 10:27 
GeneralRe: Good program but limited use for paths ... Pin
daluu9-Oct-10 20:25
memberdaluu9-Oct-10 20:25 
GeneralMore Reliable Organisation SMS Text Pin
Ian McLauchlan16-Jul-09 3:17
memberIan McLauchlan16-Jul-09 3:17 
GeneralRe: More Reliable Organisation SMS Text Pin
daluu16-Jul-09 17:08
memberdaluu16-Jul-09 17:08 
GeneralSending SMS or building SMS tool with AutoSMS API Pin
daluu14-Mar-09 17:21
memberdaluu14-Mar-09 17:21 
GeneralSending SMS through the network carrier Pin
sujayg13-Nov-08 20:51
membersujayg13-Nov-08 20:51 
GeneralRe: Sending SMS through the network carrier Pin
daluu14-Nov-08 10:04
memberdaluu14-Nov-08 10:04 
GeneralQuite useless code! Pin
Elmue17-Jul-08 12:49
memberElmue17-Jul-08 12:49 
GeneralRe: Quite useless code! Pin
daluu17-Jul-08 14:28
memberdaluu17-Jul-08 14:28 
GeneralRe: Quite useless code! Pin
Elmue29-Jul-08 9:36
memberElmue29-Jul-08 9:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 30 Dec 2007
Article Copyright 2006 by daluu
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid