NOTE: Work in progress. Please add/modify code to improve the examples.

This page describes how to manage multiple email accounts with wanderlust, one of them being a Google mail account.

Configuring folders (IMAP)

The .folders file tells wanderlust how to represent the folders. The following is an example of using just IMAP folders, as opposed to download the emails (e.g. with offlineimap) for permanent storage. Note that even when you just use IMAP folders wl downloads the messages you read (and the one following) and cache them locally to ~/.elmo/cache.

On Gmail, the default system folders (sent, trash, etc) are locale specific, i.e. the name depends on your language settings in gmail, and these folders are placed in the folder “[Gmail]”. Folders (called “filters” by Gmail) are delimited by “/”.

In the example of the other domain (company.com), the username is an email address itself and must be in quotation marks.


# -*- conf-unix -*-
   %INBOX:myname/clear@imap.gmail.com:993!         "In"
   %[Gmail]/Sent:myname/clear@imap.gmail.com:993!  "Sent"
   %[Gmail]/Draft:myname/clear@imap.gmail.com:993! "Draft"
   %[Gmail]/Trash:myname/clear@imap.gmail.com:993! "Trash"
   %[Gmail]/Spam:myname/clear@imap.gmail.com:993!  "Spam"

      %buy/ebay:myname/clear@imap.gmail.com:993!     "E-bay"
      %buy/records:myname/clear@imap.gmail.com:993!  "Records"
      %buy/books:myname/clear@imap.gmail.com:993!    "Books"

      %friends/work:myname/clear@imap.gmail.com:993!       "work friends"
      %friends/university:myname/clear@imap.gmail.com:993! "university friends"
      %friends/college:myname/clear@imap.gmail.com:993!    "old friends"
      %friends/highschool:myname/clear@imap.gmail.com:993! "very old friends"

#Note: usernames with "strange" characters (like "@") must be written 
#like: "myname@company.com". Folders at my work are delimited by dot '.'.
   %INBOX:"myname@company.com"/clear@mail.company.com        "Inbox"
   %INBOX.Sent:"myname@company.com"/clear@mail.company.com   "Sent"
   %INBOX.Drafts:"myname@company.com"/clear@mail.company.com "Draft"
   %INBOX.Trash:"myname@company.com"/clear@mail.company.com  "Trash"

      %INBOX.Project1:"myname@company.com"/clear@mail.company.com "Project 1"
      %INBOX.Project2:"myname@company.com"/clear@mail.company.com "Project 2"

Configuring .wl

With the following setup, wanderlust will automatically send from the right email-account when you reply to a message. If you start a new draft, you can cycle through the list in wl-template-alist with C-c C-j. Sent messages from gmail account or work account ends up in the right folder.

TODO: This does NOT set the correct Draft folder!

It is not possible to change the draft folder using the mechanism below, unfortunately.

With the modified code below (non-header conses moved from wl-template-alist to wl-draft-config-alist), wl-draft-folder is properly set inside the draft buffer, but the draft is still not saved to the proper draft folder.


;; You should set this variable if you use multiple e-mail addresses.
(setq wl-user-mail-address-list (quote ("myname@gmail.com" "myname@company.com")))

;;(NOTE: "M-: wl-draft-parent-folder" => %INBOX:myname/clear@imap.gmail.com:993)
(setq wl-draft-config-alist
      '(((string-match "company.com" wl-draft-parent-folder)
         (template . "work"))
        ((string-match "gmail.com" wl-draft-parent-folder)
         (template . "gmail"))
        ;; automatic for replies
        (reply "\\(To\\|Cc\\|Delivered-To\\): .*company.com.*"
         (template . "work"))
        (reply "\\(To\\|Cc\\|Delivered-To\\): .*gmail.com.*"
         (template . "gmail"))))

;;choose template with C-c C-j
(setq wl-template-alist
         (wl-from . "My Name <myname@gmail.com>")
         (wl-smtp-posting-user . "myname")
         (wl-smtp-posting-server . "smtp.gmail.com")
         (wl-smtp-authenticate-type ."plain")
         (wl-smtp-connection-type . 'starttls)
         (wl-smtp-posting-port . 587)
         (wl-local-domain . "gmail.com")
         (wl-message-id-domain . "smtp.gmail.com"))
         ("Fcc" . "%INBOX.Sent:\"myname@company.com\"/clear@mail.company.com")
         (wl-from . "My Name <myname@company.com>")
         (wl-smtp-posting-user . "myname@company.com")
         (wl-smtp-posting-server . "mail.company.com")
         (wl-local-domain . "mail.company.com"))
         ("From" . wl-from))))

Single inbox, select identity when writing a new email

This is an example where you have a single inbox, but want to select an identity when writing a new email:


;; List of identities
;; choose template with C-c C-j
(setq wl-template-alist
         (wl-from . "Me <me@example.org>")
         ("From" . wl-from))
         (wl-from . "Me <me@example.com>")
         ("From" . wl-from)
         ("Organization" . "My Business Name"))
        ("Something else"
         (wl-from . "Me <chairman@example.org>")
         ("From" . wl-from)
         ("Organization" . "Ratepayers Association"))))

PGP encryption settings per account

wl-template-alist can also be used to configure per-account encryption settings. For example, you might want to automatically encrypt all email that’s sent from a particular account.

The wl-template-alist contains template names followed by a list of actions. Each action can be a cons cell that matches a mail headers (such as (wl-from . "Me <chairman@example.org>") in the example above), or it can be a function reference. This function is run when the template is selected (manually, via C-c C-j, or automatically via wl-draft-config-alist).

By adding functions that set the encryption settings for each template, encryption can be set up automatically per account:

(setq wl-template-alist
         (wl-from . "Gmail account <myname@gmail.com>")
         (wl-smtp-posting-user . "myname@gmail.com")
         (wl-smtp-posting-server . "smtp.gmail.com")
         (wl-smtp-authenticate-type ."plain")
         (wl-smtp-connection-type . 'starttls)
         (wl-smtp-posting-port . 587)
         (wl-local-domain . "gmail.com")
         (wl-message-id-domain . "smtp.gmail.com")
         ("From" . wl-from)
         ("Fcc" . nil)
         ;; Disable encryption (when switching between accounts)
         (lambda () (mime-edit-set-encrypt nil))
         (wl-from . "Encrypted account <myname@encrypted.com>")
         (wl-smtp-posting-user . "myname@encrypted.com")
         (wl-smtp-posting-server . "smtp.encrypted.com")
         (wl-smtp-authenticate-type ."plain")
         (wl-smtp-connection-type . 'starttls)
         (wl-smtp-posting-port . 587)
         (wl-local-domain . "mail.encrypted.com")
         (wl-message-id-domain . "encrypted.com")
         ("From" . wl-from)
         ("Fcc" . "%Sent:\"myname@encrypted.com\"/clear@mail.encrypted.com")
         ;; Auto-encrypt this account and add our own key ID to
         ;; recipient list otherwise we can't view the message
         (lambda () 
           (mime-edit-set-encrypt 't)
           (setq mime-edit-pgp-encrypt-to-self 't))

Dispose (delete) method list

;; How messages with disposal mark ("d") are to be handled.
;; remove = instant removal (same as "D"), thrash = move to wl-trash-folder
;; string = move to string.
(setq wl-dispose-folder-alist
      '(("^%.*company\\.com" . "%INBOX.Trash:\"myname@company.com\"/clear@mail.company.com")
        ("^%.*gmail\\.com" . "%[Gmail]/Trash:myname/clear@imap.gmail.com:993!")