Last active
August 29, 2015 14:27
-
-
Save tuksik/4eca7218571b3b1a31b7 to your computer and use it in GitHub Desktop.
send mails from command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#http://www.binarytides.com/linux-mail-command-examples/ | |
apt-get install mailutils | |
#Use | |
$ mail -s "Hello World" someone@example.com | |
Cc: | |
Hi Peter | |
How are you | |
I am fine | |
Good Bye | |
<Ctrl+D> | |
#Specify the FROM name and address | |
echo "This is the message body" | mail -s "This is the subject" mail@example.com -aFrom:sender@example.com | |
#Send mail with attachments | |
apt-get install mutt | |
#Simple | |
echo "This is mutt from universe" | mutt -s "This is mutts subject" someone@example.com | |
# | |
mutt -s "Subject" -a /path/to/file -- user@example.com < home/user/mailcontent.txt | |
[/term] | |
According to the syntax of mutt options, it is necessary to separate the files and the recipients with a double dash "--". Also the "-a" option should be last one. | |
<h4>Send mail with bash/shell scripts</h4> | |
This example demonstrates how the output of a command can be used as the message in the email. | |
Here is an easy shell script that reports disc usage over mail. | |
[pre] | |
#!/bin/bash | |
du -sh | mail -s "disk usage report" user@yourmaildomain.com | |
[/pre] | |
Open a new file and add the lines above to that file, save it and run on your box. You will receive an email that contains "du -sh" output. | |
<h3>Read mails</h3> | |
This is not something interesting and you would not be doing this in a real life scenario. | |
###Maildir-utils command### | |
apt-get install maildir-utils | |
mu find from:william subject:report | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment