ithut (.) net

Howtos and Tutorials from behind the firewall

  • Home
  • Android
    • Root Your Phone
    • Android News
  • Urdu Tutorials
  • Top Tutorials
  • Forum
  • Policies
    • Copyright Policy
    • Comment Policy
  • Contact us
Twitter Youtube RSS
Tag Archives: sendmail

How to send email from the Linux command line

Posted on October 13, 2011 by Muhamamd Zeeshan
6 comments

The Linux command line can be very powerful once you know how to use it. You can parse data, monitor processes, and do a lot of other useful and cool things using it. There often comes a need to generate a report and mail it out. It could be as simple a requirement as a notification that the day’s backup went through fine, or did not. I’ll help you get started with sending mails from the Linux command line and in shell scripts. We will also cover sending attachments from the command line. We will begin with the “mail” command.

MAIL

First run a quick test to make sure the “sendmail” application is installed and working correctly. Execute the following command, replacing “you@youremailid.com” with your e-mail address

# mail -s “Hello world” you@youremailid.com

Hit the return key and you will come to a new line. Enter the text “This is a test from my server”. Follow up the text by hitting the return key again. Then hit the key combination of Control+D to continue. The command prompt will ask you if you want to mark a copy of the mail to any other address, hit Control+D again. Check your mailbox. This command will send out a mail to the email id mentioned with the subject, “Hello world”.

To add content to the body of the mail while running the command you can use the following options. If you want to add text on your own:

# echo “This will go into the body of the mail.” | mail -s “Hello world” you@youremailid.com

And if you want mail to read the content from a file:

# mail -s “Hello world” you@youremailid.com < /home/calvin/application.log

Some other useful options in the mail command are:

-s subject (The subject of the mail)
-c email-address (Mark a copy to this “email-address”, or CC)
-b email-address (Mark a blind carbon copy to this “email-address”, or BCC)

Here’s how you might use these options:

# echo “Welcome to the world of Calvin n Hobbes” | mail -s “Hello world” calvin@cnh.com -c hobbes@cnh.com -b susie.derkins@cnh.com

 

Categories: Linux | Tags: command line, Linux, sendmail
  • Recent Posts

    • Samsung Galaxy S7 rumor roundup: price, release date, features, specs
    • How to Root any LG Mobile
    • How To Record Ptcl Smart TV(iPtv) channels on PC
    • How to change the interface metric from GUI?
    • What’s the recommended way to enable / disable services in Ubuntu?
  • Categories

    • Android
    • Android_News
    • Android_Root
    • CCNA urdu
    • Cisco
    • internet
    • iptv
    • ipv6
    • Linux
    • Networking
    • Oracle
    • perl
    • PHP
    • Proxy
    • ptcl smarttv
    • Ubuntu
    • unblock
    • Uncategorized
    • urdu_tutorials
    • Windows
  • Tags

    bad username password ccna centos cisco command line configuration register cpan cron job cron tab dbd facebook get ipv6 free internet iptv ipv6 iso image ithut.net line attenuation Linux Linux Laptop mode mount iso networking oracle perl php proxy ptcl ptcl smart tv rhel sendmail smarttv snr margin squid Tutorials ubuntu unblock facebook unblock youtube urdu Urdu Tutorials utdu windows windows 7 windows xp youtube zee.im
zee.im ithut.net