Click here to Skip to main content
15,867,686 members
Articles / Web Development / HTML

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

Rate me:
Please Sign up or sign in to vote.
3.28/5 (24 votes)
30 Dec 2007CPOL7 min read 346.1K   4.9K   123   48
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

Introduction

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 recipient@addr.com -subject "theSubject" -body "theMessage" 

-server SMTPServer@addr.com -u YourUsername -pw YourPassword

References

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" from@addr.com to@addr.com "subject" -t 

"message"

References

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 xxxxxxxxxx@vmobl.com. 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" from@addr.com 2105211202@vmobl.com "subject" -t 

"message"

References

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.

References

History

  • 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

License

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


Written By
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.

Comments and Discussions

 
GeneralGood program but limited use for paths ... Pin
Rob Kell6-Oct-10 9:27
Rob Kell6-Oct-10 9:27 
GeneralRe: Good program but limited use for paths ... Pin
daluu9-Oct-10 19:25
daluu9-Oct-10 19:25 
GeneralMore Reliable Organisation SMS Text Pin
Ian McLauchlan16-Jul-09 2:17
Ian McLauchlan16-Jul-09 2:17 
GeneralRe: More Reliable Organisation SMS Text Pin
daluu16-Jul-09 16:08
daluu16-Jul-09 16:08 
GeneralSending SMS or building SMS tool with AutoSMS API Pin
daluu14-Mar-09 16:21
daluu14-Mar-09 16:21 
GeneralSending SMS through the network carrier Pin
SujayG13-Nov-08 19:51
SujayG13-Nov-08 19:51 
GeneralRe: Sending SMS through the network carrier Pin
daluu14-Nov-08 9:04
daluu14-Nov-08 9:04 
GeneralQuite useless code! Pin
Elmue17-Jul-08 11:49
Elmue17-Jul-08 11:49 
GeneralRe: Quite useless code! Pin
daluu17-Jul-08 13:28
daluu17-Jul-08 13:28 
GeneralRe: Quite useless code! Pin
Elmue29-Jul-08 8:36
Elmue29-Jul-08 8:36 
GeneralRe: Quite useless code! Pin
daluu29-Jul-08 12:13
daluu29-Jul-08 12:13 
GeneralRe: Quite useless code! Pin
Elmue4-Aug-08 9:27
Elmue4-Aug-08 9:27 
GeneralRe: Quite useless code! Pin
daluu4-Aug-08 12:02
daluu4-Aug-08 12:02 
GeneralIf you want to send SMS messages to cellphones Pin
William Ike8-Mar-08 21:54
William Ike8-Mar-08 21:54 
GeneralRe: If you want to send SMS messages to cellphones Pin
daluu11-Mar-08 13:03
daluu11-Mar-08 13:03 
GeneralGreat program ! Pin
John_Mann_JM4-Mar-08 8:55
John_Mann_JM4-Mar-08 8:55 
GeneralStupidity Pin
Bob Carter4-Jan-08 5:08
Bob Carter4-Jan-08 5:08 
Generalfind the carrier based on the number Pin
D.Sridhar7-Nov-07 8:32
D.Sridhar7-Nov-07 8:32 
GeneralRe: find the carrier based on the number Pin
daluu7-Nov-07 17:57
daluu7-Nov-07 17:57 
GeneralCSMTPConnection::Connect fails Pin
Raju Sai18-Oct-07 2:38
Raju Sai18-Oct-07 2:38 
GeneralRe: CSMTPConnection::Connect fails Pin
daluu18-Oct-07 7:26
daluu18-Oct-07 7:26 
GeneralSending SMS using command line. Pin
Adam Page16-Oct-07 8:08
Adam Page16-Oct-07 8:08 
GeneralRe: Sending SMS using command line. Pin
daluu16-Oct-07 12:23
daluu16-Oct-07 12:23 
GeneralRe: Sending SMS using command line. Pin
Adam Page16-Oct-07 20:21
Adam Page16-Oct-07 20:21 
Generalsms carrier addresses Pin
VEMS30-Aug-07 5:14
VEMS30-Aug-07 5:14 

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.