使用 mutt 收发邮件

由于本人用的是 gmail,下面是 gmail 的配置(以 # 开头的行是注释):

1. 使用 gmail

# ~/.muttrc

# ================  IMAP ====================

set imap_user = "<your-mail-name>@gmail.com"
set imap_pass = '<your-app-password>'

# ================  SMTP  ====================

set smtp_url = "smtp://<your-mail-name>@smtp.gmail.com:587/"
set smtp_pass = '<your-app-password>'
set ssl_force_tls = yes # Require encrypted connection

# ================ GMail =====================

set folder = "imaps://imap.gmail.com/"
# 根据 mutt 中邮箱列表是中文还是英文来配置
set spoolfile = "+INBOX" # 或者 "+[Gmail]/所有邮件"
set record = "+[Gmail]/已发邮件"
set postponed = "+[Gmail]/草稿"
set mbox = "+[Gmail]/所有邮件"
set trash = "+[Gmail]/已删除邮件" 

# ================  Composition  ====================

set editor = emacs
set edit_headers = yes  # See the headers when editing
set charset = UTF-8     # value of $LANG; also fallback for send_charset
set include # 回复时包含原文
# Sender, email address, and sign-off line must match
unset use_domain        # because joe@localhost is just embarrassing
set realname = "<your-real-name>"
set from = "<your-mail-name>@gmail.com"
set use_from = yes

2. 一般流程

如果使用非 gmail 的邮箱,可以参考下面的流程。mutt 是流程的中心,负责展示邮件和定义操作(例如收发和标记邮件等),但是并不执行实际的操作,真正的操作是由下面的程序完成的:

  • fetchmail:从指定的邮箱收取邮件;
  • maildrop:将 fetchmail 收到的邮件存到指定的地方,可以让 mutt 读取到;
  • msmtp:发送邮件。

这里只记录所用到的配置,比较简单。

2.1 fetchmail

配置文件是 ~/.fetchmailrc,下面是示例配置:

poll imap.gmail.com
protocol IMAP
user "<your@email>" is "root" here
password "<your-password>"
keep
ssl
mda "/usr/bin/maildrop"

fetchmail 只负责收邮件,还需要调用 maildrop 来将邮件分发到对应的本机账户。

fetchmail 不会主动运行,只有手动运行后才会收取新邮件。

2.2 maildrop

maildrop 用于将 fetchmail 取回来的邮件存储到对应的文件中。配置文件是 ~/.mailfilter

DEFAULT=/var/spool/mail/<username>
logfile "/var/log/maildrop.log"

2.3 msmtp

配置文件是 ~/.msmtprc

# Example for a user configuration file
# Set default values for all following accounts.
defaults
tls on
tls_starttls on
tls_trust_file /etc/ssl/certs/ca-certificates.crt
logfile /var/log/msmtp.log
# My email service
account gmail
host smtp.gmail.com
port 587
auth on
user <your@email>
password <your-password>
from <your@email>
# Set a default account
account default : gmail

2.4 mutt

mutt 的配置文件是 ~/.muttrc

set use_from = yes
set envelope_from = yes
set include # 回复的时候包含原文
set charset = "utf-8"

set realname = "<yourname>"
set from = "<your@email>"
set spoolfile = /var/spool/mail/<username> # 这里的路径就是 maildrop 中指定的路径
set sendmail = "/usr/bin/msmtp" # 指定使用 msmtp 发送邮件

参考资料

[1] Email clients info for Linux

[2] Ubuntu 不用梯子配置git send-email 发送邮件

[3] 在墙内用gmail两步认证发送kernel patch

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注