How to access Gmail from Ubuntu Terminal

Problem

I need to send email with attachment from Ubuntu terminal. I've tried ssmtp with uuencode however it didn't work very well as attachment with noname appeared before the actual attachment.

I've just tried another email client called mutt and it has been working very well so far. The following solution is to remind me and you of the steps of installing, configuring, and testing mutt.

Solution

1. Download and install mutt

sudo apt-get install mutt

2. When prompted, select internet site and type in the mail name: gmail.com

3. Creating folders and files

mkdir -p ~/.mutt/cache/headers
mkdir ~/.mutt/cache/bodies
touch ~/.mutt/certificates
touch ~/.mutt/muttrc

4. Use nano to edit mutt configuration file:

nano ~/.mutt/muttrc

and type in (or copy and paste) the followings:

set from = "YourGmailAddress@gmail.com"
set realname = "YourGmailAddress"
set imap_user = "YourGmailAddress@gmail.com"
set imap_pass = "YourGmailPassword"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "imaps://imap.gmail.com/INBOX"
set postponed = "+[Gmail]/Drafts"
set header_cache = "~/.mutt/cache/headers"
set message_cachedir = "~/.mutt/cache/bodies"
set certificate_file = "~/.mutt/certificates"
set smtp_url = "smtp://YourGmailAddress@gmail.com@smtp.gmail.com:587/"
set smtp_pass = "YourGmailPassword"
set move = no
set imap_keepalive = 900

Ctrl-X to exit and Y to save changes.

5. Ensure you have turned on Less secure app access setting on https://myaccount.google.com/security

6. To test it just type the following command:

mutt

and you'll be accessing your GMail via mutt application running on terminal

or test sending email with attachment using the following command:

printf "Email Body Test Line 1\nLine2\nLine3" | mutt -s "Email Subject TEST" RecipientEmailAddress@gmail.com -a /path/to/the/attachment/filename

7. Finish.

Comments

Popular posts from this blog

How to search Active Directory group members using Windows 10 built-in tools

How to check and reload PAC (Proxy Auto Configuration) file on Windows