Fully automatic mail workflow on macOS -- the hard way

為什麼用 postfix

因為是 macOS 自带的,不用白不用。

為什麼用 launchd/launchctl

因為 macOS 独此一家,別的 OS 上想用也沒得用。

那為啥一定要用 fetchmail 呢,getmail 不好麼?

因為用了 getmail 就沒機會用 postfix 了。:sweat_smile:

准备

notmuch & fetchmail,其他 macOS 都有。

fetchmailrc

set postmaster "ldbeth"

poll pop.qq.com with proto pop3
    user "[email protected]" there with password "***********" is "ldbeth" here options ssl

org.ldbeth.fetchmail.plist、org.ldbeth.postfix.master.plist、org.ldbeth.notmuch.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.ldbeth.fetchmail</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/pkg/bin/fetchmail</string>
        <string>-d</string>
        <string>900</string>
        <string>-f</string>
        <string>/Users/ldbeth/.fetchmailrc</string>
        <string>--syslog</string>
    </array>
    <key>KeepAlive</key>
    <true/>
    <key>UserName</key>
    <string>ldbeth</string>
    <key>EnvironmentVariables</key>
    <dict>
      <key>LC_ALL</key>
      <string>C</string>
    </dict>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.ldbeth.postfix.master</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/libexec/postfix/master</string>
        <string>-e</string>
        <string>60</string>
    </array>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SockServiceName</key>
            <string>smtp</string>
            <key>SockType</key>
            <string>stream</string>
        </dict>
    </dict>
    <key>QueueDirectories</key>
    <array>
        <string>/var/spool/postfix/maildrop</string>
    </array>
    <key>AbandonProcessGroup</key>
    <true/>
</dict>
</plist>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>org.ldbeth.notmuch</string>
    <key>ProgramArguments</key>
    <array>
        <string>/opt/pkg/bin/notmuch</string>
        <string>new</string>
    </array>
    <key>UserName</key>
    <string>ldbeth</string>
    <key>WatchPaths</key>
    <array>
        <string>/Users/ldbeth/Net/Maildir/new</string>
    </array>
    <key>StandardOutPath</key>
    <string>/var/log/mail.log</string>
    <key>StandardErrorPath</key>
    <string>/var/log/mail.log</string>
</dict>
</plist>

~/Library/LaunchAgents

postfix 配罝

http://mattshaw.org/news/how-to-filter-mail-with-postfix-header_checks/

http://www.postfix.org/VIRTUAL_README.html

工作原理:

  • 第一个 launchd.plist 负责开機启動 fetchmail Daemon,fetchmail 定時收件,投至本地 SMTP port。

  • 第二个监听本地 SMTP port 和投件箱,自动按需启用 postfix,以免一直連行的开銷。postfix 根據配置分件投件。

  • 第三个监听收件箱,有新邮件就更新 notmuch Database。并 log STDOUT & STDERR

1 个赞

现在在用imapnotify + gmailieer (GitHub - gauteh/lieer: Fast email-fetching and sending and two-way tag synchronization between notmuch and GMail) + notmuch

imapnotify 可以推送邮件 (和server差不多10s的延迟),发送系统通知,自动执行命令 (比如notmuch new和afew -a -t)

gmailieer 可以双向同步notmuch 和gmail的tags

再也不用用蛋疼的maildir文件夹结构了

imapnotify process用emacs的prodigy来管理,开启emacs自动启动

這不 UNIX。

。。。anyway, I don’t care about politics

能说下postfix是怎么用的吗?

为什么用/usr/libexec/postfix/master

我运行postfix start会返回fatal error:

postfix/postfix-script: fatal: mail system startup failed

我对这些不是很了解,我的理解是,postfix的smtp服务器监听localhost,并且fetchmail推送到localhost,postfix把邮件分发到~/Maildir/。是这样吗?

有没有什么相关的文章或者教程?

感谢。

我的postfix的配置:

home_mailbox = Maildir/
mailbox_command =

# 下面的都是默认的

queue_directory = /private/var/spool/postfix


command_directory = /usr/sbin


daemon_directory = /usr/libexec/postfix


data_directory = /var/lib/postfix


mail_owner = _postfix


debug_peer_level = 2

unknown_local_recipient_reject_code = 550

debugger_command =
	 PATH=/bin:/usr/bin:/usr/local/bin:/usr/X11R6/bin
	 ddd $daemon_directory/$process_name $process_id & sleep 5


sendmail_path = /usr/sbin/sendmail

newaliases_path = /usr/bin/newaliases

mailq_path = /usr/bin/mailq

setgid_group = _postdrop

html_directory = /usr/share/doc/postfix/html

manpage_directory = /usr/share/man

sample_directory = /usr/share/doc/postfix/examples

readme_directory = /usr/share/doc/postfix
inet_protocols = all
message_size_limit = 10485760
mailbox_size_limit = 0
biff = no
mynetworks = 127.0.0.0/8, [::1]/128
smtpd_client_restrictions = permit_mynetworks permit_sasl_authenticated permit
recipient_delimiter = +
tls_random_source = dev:/dev/urandom
smtpd_tls_ciphers = medium
inet_interfaces = loopback-only

postfix 要用 root 用户运行。然而在这里不需要用 postfix start

因為只要收邮件的 60 秒內运行 postfix 就够了,postfix start 会一直运行。

是。

http://www.postfix.org

1 个赞