Steps:
1. Install mutt: # apt-get install mutt
2. Create the file ".muttrc" in the home directory: $ touch .muttrc
3. Create the directory ".mutt/cache": $ mkdir -p .mutt/cache
4. Edit the file .muttrc with your USERNAME, PASSWORD and REALNAME:
set imap_user = "USERNAME@gmail.com"
set imap_pass = "PASSWORD"
set smtp_url = "smtp://USERNAME@smtp.gmail.com:587/"
set smtp_pass = "PASSWORD"
set from = "USERNAME@gmail.com"
set realname = "REALNAME"
set editor = "nano"
set folder = "imaps://imap.gmail.com:993"
set spoolfile = "+INBOX"
set imap_check_subscribed
set hostname = gmail.com
set mail_check = 120
set timeout = 300
set imap_keepalive = 300
set postponed = "+[GMail]/Drafts"
set record = "+[GMail]/Sent Mail"
set header_cache=~/.mutt/cache/headers
set message_cachedir=~/.mutt/cache/bodies
set certificate_file=~/.mutt/certificates
set move = no
set include
set sort = 'threads'
set sort_aux = 'reverse-last-date-received'
set auto_tag = yes
ignore "Authentication-Results:"
ignore "DomainKey-Signature:"
ignore "DKIM-Signature:"
hdr_order Date From To Cc
alternative_order text/plain text/html *
auto_view text/html
bind editor complete-query
bind editor ^T complete
bind editor noop
macro index,pager y "unset trash\n " "Gmail archive message"
macro index,pager d "set trash=\"imaps://imap.googlemail.com/[GMail]/Bin\"\n " "Gmail delete message"
macro index,pager gi "=INBOX" "Go to inbox"
macro index,pager ga "=[Gmail]/All Mail" "Go to all mail"
macro index,pager gs "=[Gmail]/Starred" "Go to starred messages"
macro index,pager gd "=[Gmail]/Drafts" "Go to drafts"
5. Send a email: $ echo "Hi, how are you?" | mutt -s "subject text" EMAILTOSEND@EMAIL.COM
6. Send a email with attached files: $ echo "Hi, how are you? I attached you a file" | mutt -s "subject text" EMAILTOSEND@EMAIL.COM -a name_file
SEND AN EMAIL WITH PYTHON
import smtplib
GMAIL_USER = 'your_name@gmail.com'
GMAIL_PASS = 'your_password'
SMTP_SERVER = 'smtp.gmail.com'
SMTP_PORT = 587
def send_email(recipient, subject, text):
smtpserver = smtplib.SMTP(SMTP_SERVER, SMTP_PORT)
smtpserver.ehlo()
smtpserver.starttls()
smtpserver.ehlo
smtpserver.login(GMAIL_USER, GMAIL_PASS)
header = 'To:' + recipient + '\n' + 'From: ' + GMAIL_USER
header = header + '\n' + 'Subject:' + subject + '\n'
msg = header + '\n' + text + ' \n\n'
smtpserver.sendmail(GMAIL_USER, recipient, msg)
smtpserver.close()
send_email('destination_email_address', 'sub', 'this is text')