sendEmail-1.56 by Brandon Zehm 
Send email from a console near you!
Written by: Brandon Zehm 
http://caspian.dotconf.net/
http://www.tsheets.com/

------------------
What is sendEmail?
------------------

SendEmail is a lightweight, completly command line based, SMTP email agent.
If you have the need to send email from the command line, this tool is perfect.
It was designed to be used in bash scripts, Perl programs, and web sites, but
it is also quite useful in many other contexts.  SendEmail is written in Perl 
and is unique in that it requires NO SPECIAL MODULES. It has an intuitive and
flexible set of command-line options, making it very easy to learn and use.

------------------
Installation
------------------

SendEmail is a perl script/program, and only needs to be copied to a directory
in your path to make it accessible.  Most likely the following steps will
be sufficient:

1) Extract the package
    tar -zxvf sendEmail-v1.XX.tar.gz

2) Copy the sendEmail script to /usr/local/bin
    cp -a sendEmail-v1.XX/sendEmail /usr/local/bin

3) Make sure its executable
    chmod +x /usr/local/bin/sendEmail

4) Run it
    sendEmail
      or
    /usr/local/bin/sendEmail

NOTES:
  * Running sendEmail without any arguments will produce a usage summary.
  * SendEmail is written in Perl, so no compilation is needed.
  * On a Unix/Linux OS if your perl binary is not installed at /usr/bin/perl
    you may need to edit the first line of the script accordingly.

---------------
Usage Overview
---------------

sendEmail-1.56 by Brandon Zehm 

Synopsis:  sendEmail -f ADDRESS [options]

  Required:
    -f ADDRESS                from (sender) email address
    * At least one recipient required via -t, -cc, or -bcc
    * Message body required via -m, STDIN, or -o message-file=FILE

  Common:
    -t ADDRESS [ADDR ...]     to email address(es)
    -u SUBJECT                message subject
    -m MESSAGE                message body
    -s SERVER[:PORT]          smtp mail relay, default is localhost:25

  Optional:
    -a   FILE [FILE ...]      file attachment(s)
    -cc  ADDRESS [ADDR ...]   cc  email address(es)
    -bcc ADDRESS [ADDR ...]   bcc email address(es)
    -xu  USERNAME             username for SMTP authentication
    -xp  PASSWORD             password for SMTP authentication

  Paranormal:
    -b BINDADDR[:PORT]        local host bind address
    -l LOGFILE                log to the specified file
    -v                        verbosity, use multiple times for greater effect
    -q                        be quiet (i.e. no STDOUT output)
    -o NAME=VALUE             advanced options, for details try: --help misc
        -o message-content-type=
        -o message-file=FILE         -o message-format=raw
        -o message-header=HEADER     -o message-charset=CHARSET
        -o reply-to=ADDRESS          -o timeout=SECONDS
        -o username=USERNAME         -o password=PASSWORD
        -o tls=         -o fqdn=FQDN

  Help:
    --help                    the helpful overview you're reading now
    --help addressing         explain addressing and related options
    --help message            explain message body input and related options
    --help networking         explain -s, -b, etc
    --help output             explain logging and other output options
    --help misc               explain -o options, TLS, SMTP auth, and more



---------------
Examples
---------------

Simple Email:
  sendEmail -f [email protected]        \
            -t [email protected]    \
            -s smtp.gmail.com:587  \
            -xu [email protected]       \
            -xp MY-PASSWORD        \
            -u "Test email"        \
            -m "Hi buddy, this is a test email."

Sending to mutiple people:
  sendEmail -f [email protected] \
            -t "Scott Thomas " [email protected] [email protected] \
            -s relay.isp.net     \
            -u "Test email"      \
            -m "Hi guys, this is a test email."

Sending to multiple people using cc and bcc recipients:
(notice the different way I specified multiple To recipients, you can do this for cc and bcc as well)
  sendEmail -f [email protected] \
            -t [email protected];[email protected];[email protected] \
            -cc [email protected] [email protected] [email protected] \
            -bcc [email protected] [email protected] [email protected] \
            -s relay.isp.net \
            -u "Test email with cc and bcc recipients" \
            -m "Hi guys, this is a test email."


Sending to multiple people with multiple attachments:
  sendEmail -f [email protected] \
            -t [email protected] \
            -cc [email protected] [email protected] [email protected] \
            -s relay.isp.net \
            -u "Test email with cc and bcc recipients" \
            -m "Hi guys, this is a test email." \
            -a /mnt/storage/document.sxw "/root/My Documents/Work Schedule.kwd"


Sending an email with the contents of a file as the message body:
  cat /tmp/file.txt | sendEmail -f [email protected] \
                                -t [email protected] \
                                -s relay.isp.net \
                                -u "Test email with contents of file"


Sending an email with the contents of a file as the message body (method 2):
  sendEmail -f [email protected] \
            -t [email protected] \
            -s relay.isp.net \
            -o message-file=/tmp/file.txt \
            -u "Test email with contents of file"


Sending an html email:  (make sure your html file has  at the beginning)
  cat /tmp/file.html | sendEmail -f [email protected] \
                                 -t [email protected] \
                                 -s relay.isp.net \
                                 -u "Test email with html content"

------------
Contributors
------------

Many thanks go to the people who have submitted ideas and patches.
I know I've forgotten to mention everyone who's helped with sendEmail,
but here is a small list.  Please let me know if you feel your name
should be here!

  v1.56
   - Several people submitted fixes for the authentication bug.
     Thanks to all of you for nagging me to get this release out!

  Simon Matter (v1.55)
   - Local bind address patch

  CBL Team  and Chris Peay (v1.55)
   - Bug reports about sendEmail causing people get blacklisted.

  Jared Cheney (v1.42)
   - More bare LF bug fixes and bare period encoding.
   - Mime encoding patch

  Buddy Nahay (v1.41)
   - Bare LF bug report

  John Rouillard (v1.41)
   - html detection bug report

  Reidar Johansen (v1.40)
   - Added support for HTML email
   - Created a function called tz_offset that determines the local timezone
   - Many other fixes and suggestions

  Paul Kreiner (v1.40)
   - Submitted a patch that forces the timestamp string to always follow
     the HH:MM:SS convention required by the RFCs.

  Al Danial
   - Found and reported a logging/typo/attachment issue in v1.32

  Svante Gerhard
   - Found and reported the file attachment/padding issue in v1.31

  Charles Leeds
   - Put together all the original file attachment code and got me
     on the path to v1.3x
   - Provided the compiled Windows executable version of sendEmail
     for a LONG time.  I really appreciate your help!

  Nick Pasich
   - Passing the email message via STDIN
   - Multiple  recpients
   - Log file option
   - Quiet option
   - Cc option
   - Lots of other suggestions and code

  Richard Duim
   - For mime/content-type/attachment suggestions

  Ulisses Montenegro
   - First one to report problems with bare LF's on qmail servers

  Michael Santy
   - Reported problems with various SMTP servers and helped me fix a few
     fairly serious problems.

  Many other people have submitted bug reports and helped to make sendEmail
  what it is today, and my best regards go out to all those .. complainers :-)
  
  
  How do I install it?

Simply download, extract, and run "sendEmail" from a command prompt, it will give a usage summary. It is written in Perl, so no compilation needed. On a unix system if your perl binary is not installed at /usr/bin/perl you may need to edit the first line of the script. If you're running a Microsoft OS you may need to put a .pl extension on sendEmail so Windows will know to associate it with perl.

TLS Support
Starting with sendEmail v1.54, TLS support is included! To enable TLS support simply install the
 Net::SSLeay and IO::Socket::SSL perl modules.
 The following new command line parameters are now available:
    -o tls=auto This is the default, TLS will be used if possible.
    -o tls=yes Use this to require TLS for message delivery.
    -o tls=no Use this to disable TLS support.
If TLS is giving strange errors, try upgrading the Net::SSLeay and IO::Socket::SSL perl modules.
Please do NOT report TLS bugs unless you have already done this! If you're running up-to-date versions
of these modules and you are getting TLS errors, your detailed bug report will be appreciated.
Yes, you can finally use SendEmail to send messages to your GMail account :)

Frequently Asked Questions
Q: How do I send email through GMail (Google Mail) servers?
A: Just use port 587 and TLS. Example:
sendEmail -o tls=yes -f [email protected] -t [email protected] -s smtp.gmail.com:587 -xu [email protected] -xp YOURPASSWORD -u "Hello from sendEmail" -m "How are you? I'm testing sendEmail from the command line."

Q: I get the error "invalid SSL_version specified at /System/Library/Perl/Extras/5.16/IO/Socket/SSL.pm line 332. on my Apple. What do I do?
A: Here's what I got from one user. It's a workaround until I put a real fix in:
> Fixed it by using Perl v5.12 that's still on OSX Mavericks. > (just changed sendEmail line 1 from #!/usr/bin/perl -w to #!/usr/bin/perl5.12 -w)

Q: Can I use non-ascii characters, like è, in an email message body?
A: It's been reported that adding the command-line parameter -o message-charset=utf-8 solves this issue.

Q: I'm using the Windows version of sendEmail and I can't seem to send a message larger than 16kb.
A: This is a known issue. I believe it's an issue with the ActiveState Perl compiler, and I don't know of a work-around.

Q: I'm using the Windows version of sendEmail, and I get the error message "the ordinal 2586 could not be located in the dynamic link libraby LIBEAY32.dll", what do I do?
A: I don't know why this happens, but you can fix it by downloading the "No TLS Support" version of sendEmail. You won't be able to send email through an SMTP server that requires encryption, but it won't give you that error message.
Why not use sendmail?
Sendmail is a large and complex mail server. Installing this kind of mail software on servers (unless it's a mail server) is more of a security risk than it's worth. Not to mention it can be a real pain messing with configuration files and such. Systems need another simpler way to send email from the command prompt, and sendEmail provides this functionality. Its a simple, direct way to send email without the overhead of other conventional email software.

How can I send anonymous email?
SendEmail was not intended to be used for malicious purposes, like sending spam! However, there are often legitimate reasons to send email anonymously. I use the term "anonymous" to mean sending email from an address that isn't normally associated with just you. For example, sendEmail is a great script for emailing company newsletters where you want to send email from an "anonymous" account like [email protected].
To send "anonymous" email from a CLI with sendEmail, simply specify a from address that you want to use with the -f option, and unless your ISP's SMTP email server is picky, it will accept and deliver it.
View Example

 

Encrypted Email
Thomas Jens Lauritsen has provided instructions on how to send SMIME signed email messages with sendEmail:
View Details