Multiple accounts

51 views
Skip to first unread message

Henrik Frisk

unread,
Jul 8, 2015, 9:07:44 AM7/8/15
to mu-di...@googlegroups.com
Hi,

After having had a working setup with multiple accounts but just one SMTP server it was necessary for me to set mu4e up with multiple accounts and multiple SMTP servers. I followed the instructions here:

http://www.djcbsoftware.nl/code/mu/mu4e/Multiple-accounts.html

which appears to be working fine, except for old messages which I cannot reply to since they lack the necessary maildir folder. Could someone here help me make a small addition so that instead of the error message I get to choose the account to send from, as if it was a new message?

The code is (copied from the link above):

(defun my-mu4e-set-account ()
  "Set the account for composing a message."
  (let* ((account
          (if mu4e-compose-parent-message
              (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
                (string-match "/\\(.*?\\)/" maildir)
                (match-string 1 maildir))
            (completing-read (format "Compose with account: (%s) "
                                     (mapconcat #'(lambda (var) (car var))
                                                my-mu4e-account-alist "/"))
                             (mapcar #'(lambda (var) (car var)) my-mu4e-account-alist)
                             nil t nil nil (caar my-mu4e-account-alist))))
         (account-vars (cdr (assoc account my-mu4e-account-alist))))
    (if account-vars
        (mapc #'(lambda (var)
                  (set (car var) (cadr var)))
              account-vars)
      (error "No email account found"))))

In the meantime I will continue working with it and see what I can come up with...
I think this would be usful for many!

Best,
/Henrik

Joost Kremers

unread,
Jul 8, 2015, 5:59:30 PM7/8/15
to mu-di...@googlegroups.com

On Wed, Jul 08 2015, Henrik Frisk <fri...@gmail.com> wrote:
> Hi,
>
> After having had a working setup with multiple accounts but just one SMTP
> server it was necessary for me to set mu4e up with multiple accounts and
> multiple SMTP servers. I followed the instructions here:
>
> http://www.djcbsoftware.nl/code/mu/mu4e/Multiple-accounts.html
>
> which appears to be working fine, except for old messages which I cannot
> reply to since they lack the necessary maildir folder. Could someone here
> help me make a small addition so that instead of the error message I get to
> choose the account to send from, as if it was a new message?

Well, since I originally wrote that code, I might as well volunteer. ;-)

> I think this would be usful for many!

Actually, it never occurred to me that someone might want to reply to a
message that's not in an account folder. I do put old messages in an
Archive folder that is not linked to any account, but those messages are
so old I never even look at them, let alone reply to them...

Anyway, the following seems to work:


```
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(let* ((accounts (mapcar #'car my-mu4e-account-alist))
(account
(or (and mu4e-compose-parent-message
(let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
(string-match "/\\(.*?\\)/" maildir)
(car (member (match-string 1 maildir) accounts))))
(completing-read (format "Compose with account: (%s) "
(mapconcat #'identity accounts "/"))
accounts
nil t nil nil (car accounts))))
(account-vars (cdr (assoc account my-mu4e-account-alist))))
(if account-vars
(mapc #'(lambda (var)
(set (car var) (cadr var)))
account-vars)
(error "No email account found"))))
```

Let me know if you run into any trouble.


--
Joost Kremers
Life has its moments

Henrik Frisk

unread,
Jul 9, 2015, 5:14:52 AM7/9/15
to mu-di...@googlegroups.com
Actually, it never occurred to me that someone might want to reply to a
message that's not in an account folder. I do put old messages in an
Archive folder that is not linked to any account, but those messages are
so old I never even look at them, let alone reply to them...

Well, for me it's because I have all my incoming mail in the same folder and need to go back to these ever so often.
 
Anyway, the following seems to work:


```
(defun my-mu4e-set-account ()
  "Set the account for composing a message."
  (let* ((accounts (mapcar #'car my-mu4e-account-alist))
         (account
          (or (and mu4e-compose-parent-message
                   (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
                     (string-match "/\\(.*?\\)/" maildir)
                     (car (member (match-string 1 maildir) accounts))))
              (completing-read (format "Compose with account: (%s) "
                                       (mapconcat #'identity accounts "/"))
                               accounts
                               nil t nil nil (car accounts))))
         (account-vars (cdr (assoc account my-mu4e-account-alist))))
    (if account-vars
        (mapc #'(lambda (var)
                  (set (car var) (cadr var)))
              account-vars)
      (error "No email account found"))))
```

Let me know if you run into any trouble.

Great, I will take a look at that. I think it's better than what I came up with in the mean time which looks at the to: address to determine the account. I think it would be good to use both the maildir: and the to:  This is just an adaptation of what is found elsewhere in the manual. Calling it instead of (mu4e-message-field mu4e-compose-parent-message :maildir) works fine it appears.

(defun my-get-account ()
     "Get the account based on the To address of the original."
     (let ((msg mu4e-compose-parent-message))
       (when msg
       (cond
         ((mu4e-message-contact-field-matches msg :to "ADDDRESS")
         "/fsdata/sent")
         ((mu4e-message-contact-field-matches msg :to "ADDRESS")
         "/kmh/sent")
        ((mu4e-message-contact-field-matches msg :to "ADDRESS")
         "/fsk/sent")))))

But I will look at your suggestion. It's probably much more solid than my hack... ;)

Thanks,
/Henrik

Damien Cassou

unread,
Jul 9, 2015, 10:42:57 AM7/9/15
to mu-di...@googlegroups.com

Henrik Frisk <fri...@gmail.com> writes:

> In the meantime I will continue working with it and see what I can
> come up with...
> I think this would be usful for many!

with multimu4e (https://github.com/DamienCassou/multimu4e), you just
have to type C-c F to force the account with which to send an email
(this also changes the From: field).

--
Damien Cassou
http://damiencassou.seasidehosting.st

"Success is the ability to go from one failure to another without
losing enthusiasm." --Winston Churchill

Henrik Frisk

unread,
Jul 10, 2015, 4:43:42 AM7/10/15
to mu-di...@googlegroups.com
On Thu, Jul 9, 2015 at 4:42 PM, Damien Cassou <dam...@cassou.me> wrote:

Henrik Frisk <fri...@gmail.com> writes:

> In the meantime I will continue working with it and see what I can
> come up with...
> I think this would be usful for many!

with multimu4e (https://github.com/DamienCassou/multimu4e), you just
have to type C-c F to force the account with which to send an email
(this also changes the From: field).

Ah, I read about that, but wasn't sure what its state of development. I have a solid setup now (I think) but next time I'm making changes I will look at your adaption! Thanks!

/Henrik

Henrik Frisk

unread,
Jul 10, 2015, 4:45:07 AM7/10/15
to mu-di...@googlegroups.com
Anyway, the following seems to work:


```
(defun my-mu4e-set-account ()
  "Set the account for composing a message."
  (let* ((accounts (mapcar #'car my-mu4e-account-alist))
         (account
          (or (and mu4e-compose-parent-message
                   (let ((maildir (mu4e-message-field mu4e-compose-parent-message :maildir)))
                     (string-match "/\\(.*?\\)/" maildir)
                     (car (member (match-string 1 maildir) accounts))))
              (completing-read (format "Compose with account: (%s) "
                                       (mapconcat #'identity accounts "/"))
                               accounts
                               nil t nil nil (car accounts))))
         (account-vars (cdr (assoc account my-mu4e-account-alist))))
    (if account-vars
        (mapc #'(lambda (var)
                  (set (car var) (cadr var)))
              account-vars)
      (error "No email account found"))))
```

Let me know if you run into any trouble.

Thanks, this is perfect. Much better than my hack and exactly how I wanted it to work. Thanks a lot!

/Henrik

Damien Cassou

unread,
Jul 10, 2015, 7:53:54 AM7/10/15
to mu-di...@googlegroups.com
I did that a few days ago in my never-ending process of cleaning my
init.el. No rocket science there.

Spencer Boucher

unread,
Aug 11, 2015, 12:45:02 AM8/11/15
to mu-discuss, dam...@cassou.me
I can't get this my-mu4e-set-account function to actually reset any variables. When I play around with it in the scratch buffer, the correct list of pairs is displayed, but they aren't actually set.

Damien Cassou

unread,
Aug 11, 2015, 1:20:53 PM8/11/15
to mu-di...@googlegroups.com
Hi Spencer,

Spencer Boucher <spencer....@gmail.com> writes:

> I can't get this my-mu4e-set-account function to actually reset any
> variables. When I play around with it in the scratch buffer, the correct
> list of pairs is displayed, but they aren't actually set.

could you please try with https://github.com/DamienCassou/profile (I
deprecated multimu4e). Also, please make sure you have dots between each
variable name and its value as shown in the README:

(mu4e-sent-folder . "/Account1/Saved Items")

and not

(mu4e-sent-folder "/Account1/Saved Items") <-- wrong
Reply all
Reply to author
Forward
0 new messages