Make the installations needed:
$ sudo apt-get install msmtp

Now create a file named .msmtprc in your home directory (~/.msmtprc) and paste the following lines. This settings are available for sending emails by a gmail account.
Replace:
- Linux Geekster : with the name you want the guy getting the mail to see
- [email protected] : your valid gmail, from which the mail will be sent
- yourpassword : the password for your valid gmail
host smtp.gmail.com
port 587
protocol smtp
auth on
from Linux Geekter
user [email protected]
password yourpassword
tls on
tls_nocertcheck
This are the setting you have to make for sending emails by a yahoo account, paste this in your ~/.msmtprc.
Replace:
- Linux Geekster : with the name you want the guy getting the mail to see
- [email protected] : your valid yahoo mail, from which the mail will be sent
- yourpassword : the password for your valid yahoo mail
host smtp.mail.yahoo.com
port 465
protocol smtp
auth on
from Linux Geekter
user [email protected]
password yourpassword
tls on
tls_nocertcheck
Next, write “set sendmail=/usr/bin/msmtp” (with no quotes ” “) in the ~/.mailrc file:
$ echo "set sendmail=/usr/bin/msmtp" > ~/.mailrc
Now set read-write permissions for the user and cancel all the permissions for the group and others (600) to the ~/.msmtprc file:
$ chmod 600 .msmtprc
How to send emails from the terminal:
This is how to send emails from terminal: echo “message” | mail [email protected]”
$ echo "Hello geeks" | mail [email protected]
For attaching files in the mails sent by terminal, use this syntax: echo “message” | mail -a /path/to/file [email protected]:
$ echo "Hello geeks, this is the LinuxG PDF Guide" | mail -a ~/linuxg.pdf [email protected]
Create mail aliases for a easier mail sending:
An alias is a shorter name for an email address. The aliases must be put in the ~/.mailrc file.
Alias syntax: alias alias_name [email protected]
Examples:
$ echo "alias mike [email protected]" >> ~/.mailrc
$ echo "alias car [email protected]" >> ~/.mailrc
$ echo "alias red [email protected]" >> ~/.mailrc
How to use the mail aliases:
Send “hello mike” to mike ([email protected]):
$ echo "hello mike" | mail mike
Bonus Trick: Write the content of a file in the mail (like: opening text file, select all and copy the text, paste it in your mail box) :
$ cat mail.txt | tee mail make
$ cat mail2.txt | tee mail [email protected]