Skip to content

Instantly share code, notes, and snippets.

@lazyfrost
Last active November 16, 2023 19:25
Show Gist options
  • Save lazyfrost/ca4807e185d5e6816bf1 to your computer and use it in GitHub Desktop.
Save lazyfrost/ca4807e185d5e6816bf1 to your computer and use it in GitHub Desktop.
Configuring mutt to work with gmail and yandex

Configuring mutt to work with gmail and yandex

Information used:

So, thanks to authors for ideas and detailed tutorials how to get it working.

This mutt configuration is for 2 email accounts - gmail.com and yandex.ru,
using folder-hooks and account-hooks to switch between them.
It is simple and quick setup.

Structure of files and folders:

~/  
 |--.mutt/  
     |-- accounts.gpg
     |-- aliases 
     |-- muttrc
     |-- yandex  
     |-- gmail
     |-- mailcap  
     |-- gmail.com/  
     |   |-- cache/  
     |       |-- bodies/  
     |       |-- headers  
     |-- yandex.ru/  
     |   |-- cache/  
     |       |-- bodies/  
     |       |-- headers   
     

Files content:


accounts

set my_name        = 'Your Name'  
set my_gmail_user  = 'your_login@gmail.com'  
set my_gmail_pass  = 'your_password_here'  
set my_yandex_user = 'your_login@yandex.ru'  
set my_yandex_pass = 'your_password_here'  

Encrypt this file with your personal key, or optionally generate new pair of key for this case:

gpg --gen-key  
gpg -e -r 'Your Name' accounts 
shred accounts && rm -f accounts  

muttrc

source "gpg -dq $HOME/.mutt/accounts.gpg |"

folder-hook 'gmail.com' 'source ~/.mutt/gmail'
folder-hook 'yandex.ru' 'source ~/.mutt/yandex'

source '~/.mutt/gmail'

account-hook gmail.com 'set imap_user=$my_gmail_user imap_pass=$my_gmail_pass'
account-hook yandex.ru 'set imap_user=$my_yandex_user imap_pass=$my_yandex_pass'

macro index <f2> '<change-folder>imaps://imap.gmail.com<enter>'
macro index <f3> '<change-folder>imaps://imap.yandex.ru<enter>'

set alias_file    = ~/.mutt/aliases
set sort_alias    = alias
set reverse_alias = yes
source $alias_file
set mailcap_path  = ~/.mutt/mailcap
auto_view text/html

gmail

# GENERAL OPTIONS
set header_cache     = ~/.mutt/gmail.com/cache/headers
set message_cachedir = ~/.mutt/gmail.com/cache/bodies
unset record

# RECEIVE OPTIONS
set imap_check_subscribed
unset imap_passive
set imap_keepalive = 900
set mail_check     = 1800

# REMOTE GMAIL FOLDERS
set folder    = 'imaps://imap.gmail.com:993'
set spoolfile = '+INBOX'
set postponed = '+[Gmail]/Черновики'

# SEND OPTIONS
set realname  = $my_name
set from      = $my_gmail_user
set smtp_url  = 'smtp://'$my_gmail_user'@smtp.gmail.com:587/'
set smtp_pass = $my_gmail_pass

yandex

# GENERAL OPTIONS
set header_cache     = ~/.mutt/yandex.ru/cache/headers
set message_cachedir = ~/.mutt/yandex.ru/cache/bodies

# RECEIVE OPTIONS
set imap_check_subscribed
unset imap_passive
set imap_keepalive = 900
set mail_check     = 1800

# REMOTE YANDEX FOLDERS
set folder    = 'imaps://imap.yandex.ru:993'
set spoolfile = '+INBOX'
set postponed = '+Черновики'
set record    = '+Отправленные'

# SEND OPTIONS
set ssl_starttls  = yes
set ssl_force_tls = yes
set realname      = $my_name
set from          = $my_yandex_user
set smtp_url      = 'smtps://'$my_yandex_user'@smtp.yandex.ru:465/'
set smtp_pass     = $my_yandex_pass

mailcap

text/html; w3m -I %{charset} -T text/html; copiousoutput;

Finally, create folders and files for headers and bodies cache

That's all. To switch between accounts press F2 and F3

@srishti9612
Copy link

srishti9612 commented Feb 10, 2017

I am unable to login mutt , it is giving me login failed !
without any errors

@xr5pl
Copy link

xr5pl commented May 23, 2017

thx, :)

@moein9
Copy link

moein9 commented Jul 23, 2020

I am unable to login mutt , it is giving me login failed !
without any errors

goto your Yandex settings and enable all options
Mail → All settings → Email clients
Use a mail client to retrieve your Yandex mail
From the imap.yandex.com server via IMAP

@vodolaz095
Copy link

is there any examples for multyple yandex configs?

@krlabs
Copy link

krlabs commented Dec 29, 2021

how fetch Spam folder?? all work perfectly, but spam folder ignore (

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment