Debian Admin

Debian/Ubuntu Linux System Administration Tutorials,Howtos,Tips

  • RSS Subscribe

    subscribe to the Debian Admin RSS feed
  • Sponsors



  • Categories

  • Sponsors

  • Support DebianAdmin

    Amount $:
    Website(Optional):


  • Meta

  • Archives



How to sendemail from the command line using a Gmail account and others

Posted by Admin on March 27th, 2009

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

SendEmail is a lightweight, completly command line based, SMTP email agent.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

Install sendemail in debian lenny

#apt-get install sendemail

This will complete the installation.

If you are using Debian Etch you need to compile sendemail from source
Preparing your system

#apt-get install libio-socket-ssl-perl libnet-ssleay-perl perl

Download latest version from here

wget http://caspian.dotconf.net/menu/Software/SendEmail/sendEmail-v1.55.tar.gz

Uncompress the .tar.gz

#tar zxvf /tmp/sendEmail-v1.55.tar.gz

#cd /tmp/sendEmail-v1.55

Copy the sendEmail script to /usr/local/bin

#cp /tmp/sendEmail-v1.55/sendEmail  /usr/local/bin

Make sure its executable

#chmod +x /usr/local/bin/sendEmail

Sendemail Examples

Simple Email Using Gmail Account

sendEmail -f my.account@gmail.com -t myself@domain.tld \
-u this is the test tile -m “this is a test message” \
-s smtp.gmail.com \
-o tls=yes \
-xu usernameonly -xp mypasswd

“usernameonly” must not contain @gmail.com only the username.

Simple Email

sendEmail -f myaddress@isp.net \
-t myfriend@isp.net \
-s relay.isp.net \
-u “Test email” \
-m “Hi , this is a test email.”

Sending to mutiple people

sendEmail -f myaddress@isp.net \
-t “admin <admin@isp.net>” user1@isp.net user2@isp.net \
-s relay.isp.net \
-u “Test email” \
-m “Hi this is a test email.”

Sending to multiple people using cc and bcc recipients

(notice the different way we specified multiple To recipients, you can do this for cc and bcc as well)

sendEmail -f myaddress@isp.net \
-t admin@isp.net;user1@isp.net;user2@isp.net \
-cc user2@isp.net tom@isp.net jess@isp.net \
-bcc ra@isp.net dub@isp.net kay@isp.net \
-s relay.isp.net \
-u “Test email with cc and bcc recipients” \
-m “Hi his is a test email.”

Sending to multiple people with multiple attachments

sendEmail -f myaddress@isp.net \
-t admin@isp.net \
-cc user1@isp.net user2@isp.net user3@isp.net \
-s relay.isp.net \
-u “Test email with cc and bcc recipients” \
-m “Hi 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 myaddress@isp.net \
-t admin@isp.net \
-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 myaddress@isp.net \
-t admin@isp.net \
-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 <html> at the beginning)

cat /tmp/file.html | sendEmail -f myaddress@isp.net \
-t admin@isp.net \
-s relay.isp.net \
-u “Test email with html content”

Send Short Message Service (SMS)/text message to a cellular phone

Simple Text Message Sent To Cellular Phone Using Gmail Account

./sendEmail -f usernameonly@gmail.com -t 2123334444@txt.att.net \
-m This is an SMS message from Linux.\
-o tls=auto \
-s smtp.gmail.com \
-xu usernameonly -xp mypasswd

Providers

What’s my SMS Email address?

AT&T 10DigitPhoneNumber@txt.att.net
Example: 9055556543@txt.att.net
Cingular 10DigitPhoneNumber@cingularme.com
Metrocall 10DigitPhoneNumber@page.metrocall.com
Nextel 10DigitPhoneNumber@messaging.nextel.com
Sprint PCS 10DigitPhoneNumber@messaging.sprintpcs.com
T-Mobile 10DigitPhoneNumber@tmomail.net
Verizon 10DigitPhoneNumber@vtext.com
ALLTEL 10DigitPhoneNumber@message.alltel.com

  • Share/Bookmark

Random Posts

4 Responses to “How to sendemail from the command line using a Gmail account and others”

  1. Luca Bruno Says:

    Also see esmtp, it’s compatible with sendmail.

  2. Ridgeland Says:

    Thank You.
    I had tried this a year or two ago and gave up easily. I am using Ubuntu 8.10, synaptics for sendemail then a hybrid of your “Simple Email using Gmail account” and “Simple Email”. I’m not using gmail but for a simple email I used fields -f -t -s -xu -xp -u -m
    -s mail.mydomain.net

  3. rossdub Says:

    I have an Etch server up and running, and followed the instructions here. They worked perfectly, and the script executed successfully, but I am not receiving the email. Perhaps there is a server or router configuration I am missing? Here is the verbose output from my test email.


    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => Connecting to localhost:25
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => My IP address is: 127.0.0.1
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => evalSMTPresponse() - Found SMTP success code: 220
    May 28 16:11:43 myprivateserver sendEmail[29676]: SUCCESS => Received: 220 myprivateserver.launchmodem.com ESMTP Exim 4.63 Thu, 28 May 2009 16:11:43 -0400
    May 28 16:11:43 myprivateserver sendEmail[29676]: INFO => Sending: EHLO myprivateserver.launchmodem.com
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
    May 28 16:11:43 myprivateserver sendEmail[29676]: SUCCESS => Received: 250-myprivateserver.launchmodem.com Hello root at localhost [127.0.0.1], 250-SIZE 52428800, 250-PIPELINING, 250 HELP
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => The remote SMTP server does NOT support TLS :(
    May 28 16:11:43 myprivateserver sendEmail[29676]: NOTICE => Authentication not supported by the remote SMTP server!
    May 28 16:11:43 myprivateserver sendEmail[29676]: INFO => Sending: MAIL FROM:
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
    May 28 16:11:43 myprivateserver sendEmail[29676]: SUCCESS => Received: 250 OK
    May 28 16:11:43 myprivateserver sendEmail[29676]: INFO => Sending: RCPT TO:
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
    May 28 16:11:43 myprivateserver sendEmail[29676]: SUCCESS => Received: 250 Accepted
    May 28 16:11:43 myprivateserver sendEmail[29676]: INFO => Sending: DATA
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => evalSMTPresponse() - Found SMTP success code: 354
    May 28 16:11:43 myprivateserver sendEmail[29676]: SUCCESS => Received: 354 Enter message, ending with "." on a line by itself
    May 28 16:11:43 myprivateserver sendEmail[29676]: INFO => Sending message body
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => Sending the attachment [webFileCheckLog.txt]
    May 28 16:11:43 myprivateserver sendEmail[29676]: DEBUG => evalSMTPresponse() - Found SMTP success code: 250
    May 28 16:11:43 myprivateserver sendEmail[29676]: SUCCESS => Received: 250 OK id=1M9lx1-0007if-EM
    May 28 16:11:43 myprivateserver sendEmail[29676]: Email was sent successfully! From: To: Subject: [test] Attachment(s): [webFileCheckLog.txt] Server: [localhost:25]

  4. Andrew Says:

    ERROR => Timeout while connecting to smtp.gmail.com:25 There was no response after 60 seconds.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>