Install msmtp
The first step is to install the msmtp-mta package.
After the install is complete you'll need to set up the defaults file with your Gmail account information. You need to create a file in your home directory called .msmtprc.
Paste the following into the file and edit the portions in bold to reflect your account information.
Save the file and exit the text editor. Since this file contains your account credentials, you'll want to change the permissions to make the file readable only by you.
Install mailx
Now that your computer is configured to talk to Gmail, you need a command line email program to handle writing your email. For this I'm going to use mailx from the heirloom-mailx package.
Now you need to set up the defaults file so that mailx uses msmtp to send out the email. This file is called .mailrc.
Now paste the following into the file and save it.
You should now be able to send email from your terminal command line.
Sending email from the command line
Now you can send email from the command line like this:
The cursor will go to a blank line. Enter your email message. When you're done, hit <Enter> to go to a blank line and then hit <Ctrl>+D to end your message. You have just sent your email.
Here you can see that I've sent an email to myself from my Gmail account.
You can also use a message saved in a text file rather than entering it interactively. This is especially useful if you're automating this process in a script. In this example, the email is saved in a file called message.txt.
This content originally appeared at http://tuxtweaks.com/2012/10/send-gmail-from-the-linux-command-line/.
没有评论:
发表评论