Click here to Skip to main content
12,293,917 members (62,361 online)
Click here to Skip to main content
Add your own
alternative version

Stats

247.7K views
4K downloads
120 bookmarked
Posted

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

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)

Share

About the Author

daluu
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 9:27
memberRob Kell6-Oct-10 9:27 
GeneralRe: Good program but limited use for paths ... Pin
daluu9-Oct-10 19:25
memberdaluu9-Oct-10 19:25 
GeneralMore Reliable Organisation SMS Text Pin
Ian McLauchlan16-Jul-09 2:17
memberIan McLauchlan16-Jul-09 2:17 
GeneralRe: More Reliable Organisation SMS Text Pin
daluu16-Jul-09 16:08
memberdaluu16-Jul-09 16:08 
GeneralSending SMS or building SMS tool with AutoSMS API Pin
daluu14-Mar-09 16:21
memberdaluu14-Mar-09 16:21 
GeneralSending SMS through the network carrier Pin
sujayg13-Nov-08 19:51
membersujayg13-Nov-08 19:51 
GeneralRe: Sending SMS through the network carrier Pin
daluu14-Nov-08 9:04
memberdaluu14-Nov-08 9:04 
GeneralQuite useless code! Pin
Elmue17-Jul-08 11:49
memberElmue17-Jul-08 11:49 
GeneralRe: Quite useless code! Pin
daluu17-Jul-08 13:28
memberdaluu17-Jul-08 13:28 
GeneralRe: Quite useless code! Pin
Elmue29-Jul-08 8:36
memberElmue29-Jul-08 8:36 
GeneralRe: Quite useless code! Pin
daluu29-Jul-08 12:13
memberdaluu29-Jul-08 12:13 
GeneralRe: Quite useless code! Pin
Elmue4-Aug-08 9:27
memberElmue4-Aug-08 9:27 
GeneralRe: Quite useless code! Pin
daluu4-Aug-08 12:02
memberdaluu4-Aug-08 12:02 
GeneralIf you want to send SMS messages to cellphones Pin
William Ike8-Mar-08 21:54
memberWilliam Ike8-Mar-08 21:54 
GeneralRe: If you want to send SMS messages to cellphones Pin
daluu11-Mar-08 13:03
memberdaluu11-Mar-08 13:03 
GeneralGreat program ! Pin
John_Mann_JM4-Mar-08 8:55
memberJohn_Mann_JM4-Mar-08 8:55 
GeneralStupidity Pin
Bob Carter4-Jan-08 5:08
memberBob Carter4-Jan-08 5:08 
Generalfind the carrier based on the number Pin
D.Sridhar7-Nov-07 8:32
memberD.Sridhar7-Nov-07 8:32 
GeneralRe: find the carrier based on the number Pin
daluu7-Nov-07 17:57
memberdaluu7-Nov-07 17:57 
GeneralCSMTPConnection::Connect fails Pin
Raju Sai18-Oct-07 2:38
memberRaju Sai18-Oct-07 2:38 
GeneralRe: CSMTPConnection::Connect fails Pin
daluu18-Oct-07 7:26
memberdaluu18-Oct-07 7:26 
GeneralSending SMS using command line. Pin
touchring16-Oct-07 8:08
membertouchring16-Oct-07 8:08 
GeneralRe: Sending SMS using command line. Pin
daluu16-Oct-07 12:23
memberdaluu16-Oct-07 12:23 
GeneralRe: Sending SMS using command line. Pin
touchring16-Oct-07 20:21
membertouchring16-Oct-07 20:21 
Generalsms carrier addresses Pin
VEMS30-Aug-07 5:14
memberVEMS30-Aug-07 5:14 
GeneralRe: sms carrier addresses Pin
Rukun9-Aug-08 19:28
memberRukun9-Aug-08 19:28 
GeneralRe: sms carrier addresses Pin
daluu9-Aug-08 19:45
memberdaluu9-Aug-08 19:45 
GeneralRunning mxmail.exe from VC++ didn't wokr. Why? [modified] Pin
ehaerim26-Feb-07 22:12
memberehaerim26-Feb-07 22:12 
GeneralRe: Running mxmail.exe from VC++ didn't wokr. Why? Pin
precords12-Sep-08 1:02
memberprecords12-Sep-08 1:02 
Questionmail message headers Pin
Camilo Vergara M.26-Feb-07 10:50
memberCamilo Vergara M.26-Feb-07 10:50 
AnswerRe: mail message headers Pin
daluu26-Feb-07 12:12
memberdaluu26-Feb-07 12:12 
Questiongreat work but i hve a problem Pin
jayu_s_a23-Feb-07 4:01
memberjayu_s_a23-Feb-07 4:01 
AnswerRe: great work but i hve a problem Pin
daluu23-Feb-07 7:54
memberdaluu23-Feb-07 7:54 
Generaldo you have codes for VC6 Pin
TongGao Tang21-Feb-07 6:05
memberTongGao Tang21-Feb-07 6:05 
GeneralRe: do you have codes for VC6 Pin
daluu21-Feb-07 7:43
memberdaluu21-Feb-07 7:43 
QuestionWhat happens when you don't know the carrier domain Pin
xaml.net13-Jan-07 2:11
memberxaml.net13-Jan-07 2:11 
AnswerRe: What happens when you don't know the carrier domain Pin
daluu13-Jan-07 14:36
memberdaluu13-Jan-07 14:36 
GeneralGreat work ! Pin
eugene_liu12-Dec-06 10:11
membereugene_liu12-Dec-06 10:11 
GeneralGot It Pin
andre1234528-Nov-06 8:36
memberandre1234528-Nov-06 8:36 
GeneralMXMail Pin
andre1234524-Nov-06 1:14
memberandre1234524-Nov-06 1:14 
GeneralRe: MXMail Pin
daluu27-Nov-06 7:57
memberdaluu27-Nov-06 7:57 
GeneralInteresting Pin
NinjaCross6-Nov-06 14:04
memberNinjaCross6-Nov-06 14:04 
GeneralRe: Interesting [modified] Pin
daluu6-Nov-06 14:34
memberdaluu6-Nov-06 14:34 
Generalthis is totally stupid Pin
my-junk-account5-Nov-06 22:52
membermy-junk-account5-Nov-06 22:52 
GeneralRe: this is totally stupid Pin
daluu6-Nov-06 8:41
memberdaluu6-Nov-06 8:41 

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.

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