Skip to content

Instantly share code, notes, and snippets.

@shrysr
Last active August 7, 2019 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shrysr/8c239fcbf1db4da15066788eeadaadc7 to your computer and use it in GitHub Desktop.
Save shrysr/8c239fcbf1db4da15066788eeadaadc7 to your computer and use it in GitHub Desktop.

07:14 Sanitised version of email config

I’d split the whole process into the following steps and would suggest that you focus on getting each step working. This will also help you troubleshoot which step is actually the problem.

  1. mbsync setup for syncing email.
  2. postfix server for sending email
  3. mu setup for indexing email in synced folder. For this mbsync has to be setup first, and the email available to index.
  4. mu4e (comes with mu) for interface in emacs. If mu is setup, mu4e should work.

This is an org file, and it should be possible to directly execute the code blocks below, particularly for the postfix, and mu4e config (after changing the relevant paths/personal info etc)

mbsync for receiving mail

Make sure you have mbysnc installed. I believe this is possible using brew install isync, though this may be an older version.

Only for the portion of the mbsync password setup: I’ve followed the instructions at Drowning in Email; mu4e to the Rescue. Refer only to the relevant parts of the section ‘configure mbsync’. My .mbsyncrc file may be more useful for actual sync channel setup.

AFAIK : only a single app specific password from fastmail is required, and this goes into the .mbsyncpass file as shown in the article above, and I have it encrypted with my key via emacs.

You may have to create the parent folder for your email.

Test that mbsync works with mbsync -V -a in the terminal.

install mu4e from source / git

Build the mu index after mu is installed. Plug in your email directory here. It is also possible to install via brew, but may result in an older version of mu.

In any case - depending on the method of installation - the load path in the Emacs configuration for Mu4e will change. This is better executed in a terminal, as it would take some time and freeze Emacs if run with an org source block.

mu index --maildir=~/my_mail/fmail/

This will create the index in ~/.mu . This folder or index can be deleted safely if you want to re-index for any reason.

This can be tested with mu find. If this works, that means your mu index is finished.

Postfix server for sending email

A version of Postfix may already be installed on your mac.

Add the following to the file /etc/postfix/main.cf, at the very end. Or just run the code block below.

cat >> /etc/postfix/main.cf << EOF
######################################################################
# fastmail configuration

relayhost = [smtp.fastmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes
EOF

The cacert.pem is a file that may already be available. I keep my cert in git and sym link this to the /etc/postfix/ location. Refer link for information on getting the certificate if unavailable.

Create the file sasl_passwd and enter the following. Note that the password has to be an app-specific password from Fastmail. The email address has to be the account email and not an alias.

sudo touch /etc/postfix/sasl_passwd
cat > /etc/postfix/sasl_passwd <<EOF
[smtp.fastmail.com]:587 abcd@fastmail.com:ABCD
EOF

Change Permissions and restart postfix if required.

sudo chmod 600 /etc/postfix/sasl_passwd
sudo postmap /etc/postfix/sasl_passwd

# Check if these commands are for Linux / Mac. It may be as simple as sudo postfix start

#sudo launchctl stop org.postfix.master
#sudo launchctl start org.postfix.master

As a test: send the folder structure. Install tree in Mac (to enable viewing a folder structure)

brew install tree

Send a test mail of a folder Structure

tree ~/temp | mail -s "Folder contents - Test email" sr@eml.cc

If the above mail is received - your postfix is setup.

relevant mu4e config

Excerpt of my config. This has to be run after the initial mu index has been completed,

Note the set location of the attachments and actual maildir. This has to be changed for your case. Also note the configuration to send mail.

(add-to-list 'load-path "/usr/local/share/emacs/site-lisp/mu4e")

(setq
 mue4e-headers-skip-duplicates  t
 mu4e-view-show-images t
 mu4e-view-show-addresses 't
 mu4e-compose-format-flowed nil
 mu4e-update-interval 200
 message-ignored-cited-headers 'nil
 mu4e-date-format "%y/%m/%d"
 mu4e-headers-date-format "%Y/%m/%d"
 mu4e-change-filenames-when-moving t
 mu4e-attachments-dir "~/Downloads/Mail-Attachments/"
 mu4e-maildir (expand-file-name "~/my_mail/fmail")
 )

;; mu4e email refiling loations
(setq
 mu4e-refile-folder "/Archive"
 mu4e-trash-folder  "/Trash"
 mu4e-sent-folder   "/Sent"
 mu4e-drafts-folder "/Drafts"
 )

;; setup some handy shortcuts
(setq mu4e-maildir-shortcuts
      '(("/INBOX"   . ?i)
        ("/Sent"    . ?s)
        ("/Archive" . ?a)
        ("/Trash"   . ?t)))

;; Config for sending email
(setq
 message-send-mail-function 'message-send-mail-with-sendmail
 send-mail-function 'sendmail-send-it
 message-kill-buffer-on-exit t
 )

;; allow for updating mail using 'U' in the main view:
(setq mu4e-get-mail-command  "mbsync -a -q")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment