logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

aerc-with-mbsync-postfix.md (3790B)


  1. ---
  2. title: aerc, mbsync, and postfix for maximum comfy offline email
  3. date: 2021-05-17
  4. ---
  5. I am the original author of the [aerc mail client][0], though my official
  6. relationship with it today is marginal at best. I think that, with hindsight,
  7. I've come to understand that the "always online" approach of aerc's IMAP
  8. implementation is less than ideal. The next email client (which will exist at
  9. some point!) will improve on this design, but, since it's still my favorite
  10. email client despite these flaws, they will have to be worked around.
  11. [0]: https://aerc-mail.org
  12. To this end, I have updated my personal aerc setup to take advantage of its
  13. [Maildir][1] support instead of having it use IMAP directly, then delegate IMAP
  14. to [mbsync][2]. This brings a much-needed level of robustness to the setup, as
  15. my Maildirs are available offline or on a flaky connection, and postfix will
  16. handle queueing and redelivery of outgoing emails in similar conditions.[^1]
  17. This allows me to read and reply to email entirely offline, and have things sync
  18. up automatically when a connection becomes available.
  19. [1]: https://en.wikipedia.org/wiki/Maildir
  20. [2]: https://isync.sourceforge.io
  21. [^1]: Postfix is probably overkill for this, but hey, it's what I know.
  22. The mbsync configuration format is kind of weird, but it is pretty flexible. My
  23. config file ended up looking like this:
  24. ```
  25. IMAPAccount migadu
  26. Host imap.migadu.com
  27. User sir@cmpwn.com
  28. Pass [...]
  29. SSLType IMAPS
  30. MaildirStore local
  31. Path ~/mail/
  32. INBOX ~/mail/INBOX
  33. SubFolders Verbatim
  34. IMAPStore migadu
  35. Account migadu
  36. Channel primary
  37. Far :migadu:
  38. Near :local:
  39. Patterns INBOX Archive Sent Junk
  40. Expunge Both
  41. ```
  42. The password can be configured to run an external command if you prefer to
  43. integrate this with your keyring or password manager. I updated my aerc
  44. `accounts.conf` as well, which was straightforward:
  45. ```
  46. [Drew]
  47. source = maildir://~/mail
  48. outgoing = /usr/sbin/sendmail
  49. from = Drew DeVault <sir@cmpwn.com>
  50. copy-to = Sent
  51. ```
  52. Running `mbsync primary` at this point is enough to fetch these mailboxes from
  53. IMAP and populate the local Maildirs, which can then be read with aerc. I set up
  54. a simple cronjob to run this every minute to keep it up to date:
  55. ```
  56. * * * * * chronic mbsync primary
  57. ```
  58. chronic is a small utility from [moreutils][3] which converts reasonably behaved
  59. programs that return a nonzero exit status into the back-asswards behavior cron
  60. expects, which is that printing text to stdout means an error occurred and any
  61. status code, successful or not, is disregarded. You might want to tweak this
  62. further, perhaps by just directing all output into /dev/null instead, if you
  63. don't want failed syncs to fill up your Unix mail spool.
  64. [3]: https://joeyh.name/code/moreutils/
  65. mbsync is bidirectional (it is recommended to leave `Expunge both` out of your
  66. config until you've tested the setup), so deleting or archiving emails in aerc
  67. will mirror the changes in IMAP as well.
  68. Postfix is a lot more annoying to configure. You should assume that what I did
  69. here isn't going to work for you without additional changes and troubleshooting.
  70. I started with an `/etc/postfix/sasl_passwd` file like this:
  71. ```
  72. [smtp.migadu.com]:465 sir@cmpwn.com:password
  73. ```
  74. The usual `postmap /etc/postfix/sasl_passwd` applies here to create or update
  75. the database file. Then I moved on to `main.cf`:
  76. ```
  77. # Allows localhost to relay mail
  78. mynetworks = 127.0.0.0/8
  79. # SMTP server to relay mail through
  80. relayhost = [smtp.migadu.com]:465
  81. # Auth options for SMTP relay
  82. smtp_sasl_auth_enable = yes
  83. smtp_sasl_password_maps = lmdb:/etc/postfix/sasl_passwd
  84. # ¯\_(ツ)_/¯
  85. smtp_tls_security_level = encrypt
  86. smtp_tls_wrappermode = yes
  87. smtp_use_tls = yes
  88. smtp_sasl_security_options =
  89. ```
  90. Good luck!
  91. **Updated 2021-05-25**: isync is not a fork of mbsync.