kamazeuci · 2022-04-03 18:14
HI! longtime Linux user and libre software activist looking to start using Emacs after LibrePlanet 2022 motivation.
My plan is to first set it up as my mail client. And I have a specific mail client requirement which so far, only Thunderbird has been able to offer ([https://www.reddit.com/r/Thunderbird/comments/n3wmc4/setting\_up\_automated\_replyfrom\_when\_using\_a/](https://www.reddit.com/r/Thunderbird/comments/n3wmc4/setting_up_automated_replyfrom_when_using_a/))
Basically:
I have my own custom domain, [mydomain.com](https://mydomain.com/), and I am using a catch-all system. So, when I communicate with the bank, I give the address [bank@mydomain.com](mailto:bank@mydomain.com). When I buy from the supermarket, I use [supermarket@mydomain.com](mailto:supermarket@mydomain.com), and so on. I have configured my server with a catch-all, so all of these emails arrive at [accounts@mydomain.com](mailto:accounts@mydomain.com), which is set up on the email client by IMAP. The problem is that, when I hit reply to any of these email messages, it defaults to replying from [accounts@mydomain.com](mailto:"accounts@mydomain.com), and not [supermarket@mydomain.com](mailto:supermarket@mydomain.com), which is what I would like the email client to do. I am able to manually change the "from" address manually, but it is one more step and frequently I forget it, exposing my global email address: [accounts@mydomain.com](mailto:accounts@mydomain.com) , to the recipient of the message, something that I do not want to happen. Is there on Emacs a way to set to default, that when replying a message it will be sent from the email address it was originally sent to?
Is there a relatively simple way to implement this?I understand Emacs is as flexible as clay, but I do not want to spend my whole week learning LISP to solve this functionality. Do not get me wrong. I do like the idea of gradually learning ELISP by the use of Emacs through years, and I understand the tweakability of it its a big part of its appeal.
If so, what email packages should I use? I think mu4e is the most recommended one on the web, should I be able to do the trick or would you recommend other mail packages?
Thanks and sorry for the long post!
ieure · 2022-04-03 19:40
I had the same need, so I hacked this up a while back:
(defun ime/mu4e-matching-address ()
"Return (TO-USER . TO-ADDR) for this message.
...but only if the email satisfies `mu4e-user-mail-address-p'."
(cl-loop for to-data in (mu4e-message-field mu4e-compose-parent-message :to)
for to-email = (cdr to-data)
when (mu4e-user-mail-address-p to-email)
return to-data))
(defun ime/mu4e-reply-from-same ()
"Use To: address from original message as From: in reply.
...but only if the email satisfies `mu4e-user-mail-address-p'."
(when mu4e-compose-parent-message
(save-excursion
(when-let ((dest (ime/mu4e-matching-address)))
(cl-destructuring-bind (to-user . to-addr) dest
(message-position-on-field "From")
(message-beginning-of-line)
(delete-region (point) (line-end-position))
(insert (format "%s <%s>" (or to-user user-full-name) to-addr)))))))
(add-hook 'mu4e-compose-mode #'ime/mu4e-reply-from-same)
This only works if the email was sent to an address mu recognizes as being yours, which you declared when running `mu init`. I have a limited (3-4) number of incoming addresses, so this is fine for me. Something like this is necessary, because emails can be sent `To` multiple addresses, but only `From` one -- so you have to pick the right address from the list of them all.
You could hack up `ime/mu4e-matching-address` if you need different semantics. Sounds like returning the first one which matches your domain is likely the right way to do it.
kamazeuci · 2022-04-03 20:02
thanks! the thing is I have a theoretically infinite number of incoming addresses. Each new business/organization I give my email to, I give them theirname@mydomain.com. The domain name is always the same though.
It is kinda fun to listen to them really confused as why my email is just like their name, but real functionality is to track contact info exposure. If I ever get spam, I will know exactly who sold my contact information.
So, I suppose your script won't work for me?
thanks again!
ieure · 2022-04-03 20:10
It will work with very minor modification, like I said, and for the reasons I mentioned.
publicvoit · 2022-04-03 20:42
I don't know about Emacs but this is how I do it with Org-mode and an external mail client (mutt) for many years: https://karl-voit.at/2015/02/01/muttfilter/
podtatranec · 2022-04-04 10:26
I didn't see which email package you plan to use. I've been using notmuch myself but many people swear by mu4e (both require you sync from imap with something like mbsync). There's also clients that allow direct usage of imap (built in gnus, or wanderlust).
Each might require slightly different setup. I actually have a similar setup as you need with my own domain and notmuch. Likely not applicable to other clients though
kamazeuci · 2022-04-04 17:47
thanks! thats part of the question, given that this specific funcion/requirement is a need, I would love to know if I should lean towards an specific email package that will allow me to sort it our easier than other.
​
thanks!
[deleted] · 2022-04-12 05:29
[removed]
chaorace · 2022-08-10 15:29
There was recently a breaking change in mu4e that changed the shape of the data in the message's "to" field. Here's a tweak to the affected function that should support both the old and new formats:
(defun ime/mu4e-matching-address ()
"Return (TO-USER . TO-ADDR) for this message if the email satisfies `mu4e-user-mail-address-p'."
(cl-loop for to-data in (mu4e-message-field mu4e-compose-parent-message :to)
for to-email = (pcase to-data
(`(_ . email) email)
(x (mu4e-contact-email x)))
when (mu4e-user-mail-address-p to-email)
return to-data))
ieure · 2022-08-10 15:34
Thanks, I'll take a look.
I recently pulled all this code out of my init file and spun up [mu4e-static](https://codeberg.org/emacs-weirdware/mu4e-static) to house it, but I haven't tested it and made sure the kinks are ironed out.
Feel free to give it a shot / open a PR if you feel motivated.