I have several accounts associated with mu4e and I can both receive and send - using smtpmail-multi - from all them without problems. I am not using contexts. The relevant parts in my configuration look like this:
(setq message-citation-line-function 'message-insert-formatted-citation-line)
(setq message-citation-line-format "On %a, %b %d %Y, %f wrote:\n")
(setq smtpmail-multi-accounts
(quote
((yahoo . ("xxxx@yahoo.com"
"smtp.mail.yahoo.com"
587
"xxxxx@yahoo.com"
nil nil nil nil))
(other . ("xxxxx@other.com"
"smtp.other.com"
465
"xxxx@other.com"
ssl nil nil nil))
(etc . ("xx@etc.com"
"smtp.etc.com"
465
"xx@etc.com"
ssl nil nil nil))
;; ...
)))
(setq smtpmail-multi-associations
(quote
(("xxxx@yahoo.com" yahoo)
("xxx@other.com" other)
("xx@etc.com" etc)
;; ....
)))
(setq smtpmail-multi-default-account (quote yahoo))
(setq message-send-mail-function 'smtpmail-multi-send-it)
(setq mu4e-compose-dont-reply-to-self t)
(setq mu4e-user-mail-address-list '("xxxx@yahoo.com"
"xxx@other.com"
"xx@etc.com"
;; ...
))
(setq user-full-name "XXXXXX")
(setq user-mail-address "xxx@other.com")
This way I can properly send emails from the right account just by typing the address of my email in the FROM:
field.
When replying, I want mu4e to identify the account to which the message has been send and update FROM:
field accordingly so that I don't have to type in the proper account all the time myself. I am looking for a way to do this without having to upgrade my entire configuration to using contexts.
After a lot of tweaking I came up with this:
(defun my-mu4e-set-account ()
"Set the account for composing a message."
(if mu4e-compose-parent-message
(let ((mail (cdr (car (mu4e-message-field mu4e-compose-parent-message :to)))))
(if (member mail mu4e-user-mail-address-list)
(setq user-mail-address mail)
(setq user-mail-address "my@default.account")))
(helm :sources
`((name . "Select account: ")
(candidates . mu4e-user-mail-address-list)
(action . (lambda (candidate) (setq user-mail-address candidate)))))))
(add-hook 'mu4e-compose-pre-hook 'my-mu4e-set-account)
where mu4e-user-mail-address-list
is, obviously, a list with my mail accounts
This will reply with the proper account and, more, will open a helm mini menu asking me which account to use every time I compose a new message.