See part 2 for a better solution.
I recently moved to using aerc for email after using mutt (and then neomutt) for some number of years. Today I decided to go beyond a simple maildir for organizing mails locally, and use the notmuch backend for aerc. I use neomutt + notmuch for $dayjob, so I'm no stranger to creating tag 'rules' and searching, etc. What I was unprepared for is that aerc does not care about sent mails after pushing them to smtp. Contrast this to mutt and it's
record setting that will save sent mails to some configured location.
The "official stance" on this seems to be either use a custom send script that saves off the mail to a sent dir, or configure something on your mail provider to store mails in the imap Sent folder. I have been using aerc as the smtp client here, but use msmtp elsewhere. Neither support any mechanism for storing sent mails. I decided that option 2 must be the "easier" route in this case.
And for once, it was! (granted, I didn't even try the first option, but I wasn't finding anything promising in the short amount of time I looked into it..)
My mail provider, mailbox.org, features a really nice filter interface for creating rules to do all sorts of things to mail on arrival. So I (ab)used this to make the following rule:
Address Header From
Part All Contains <my email address here>
To Contains not <my email address here>
Cc Contains not <my email address here>
Mark mail as seen
File into Sent
In case it's not clear above:
Move emails from my email address, but not if my email is also in the To: or Cc: header, to the Sent folder and mark them as 'read'.
The exception for having my email address in To: or Cc: is so that I can still send myself emails (for archival purposes) or Cc myself, and still receive the mail in my Inbox.
Great, so now I just have to Bcc: myself on mails in aerc, and they'll get filed into the Sent folder on the imap server. But manually adding
Bcc: <me> is tedious. One really (really) cool feature of aerc is message templates (see
man aerc-templates). The first step is to configure a user template directory in
Then create a custom template, I saved this one to
Bcc: <my email here>
The new-lines in the template are important, one new-line separates the header from the message body, and I added another just so I would have room to start typing the message immediately before my 'signature'
And finally modified the key binding (in
bind.conf) for composing a new mail to also include the template:
C = :compose -T new<Enter>
Now mails I sent from aerc are automatically filed into the Sent imap folder on the mail server. When mbsync runs, the sent mails are pulled down locally. The downside to this approach is that extra round trip to the imap server before the sent mail is stored locally on the system that sent it.... But, for now, this will do.