msmtp icon indicating copy to clipboard operation
msmtp copied to clipboard

[request] ability to work with custom headers

Open atesin opened this issue 1 year ago • 2 comments

hi... i would like the ability to add/replace custom headers

why?, i have an embedded system that sends me emails on important events, i use a known email account but i want to distinguish the mails sent by this system from other regular mails human-sent with the same account.....)

i know theoretically this can already be achieved with other existing options, but i could not make it work as i expect, additionally being able to habdle any header would be more useful/flexible .... imagine something like

from my.personal@email           # FROM address for smtp envelope
header From sensors system <%F>  # suppossing %F variable is FORM envelope value taken from above
header Cc                        # no value = delete header if present?

.... but going further, headers could also be added | added-if-not | replaced | deleted... lets say, added as default (i.e. if not defined in message), or added together (ex. to add more recipients), replaced (overwrite header message) or deleted..... maybe using more options (header-default, header-replace, etc)

atesin avatar Jul 16 '23 09:07 atesin

I like your ideas, but there are a few drawbacks:

  • This header processing somewhat contradicts the goal of msmtp to do only what is necessary.
  • The current header processing in msmtp is a handwritten finite state machine that covers exactly the minimal use cases that msmtp currently supports. It uses very few resources, but it is obviously not flexible or extensible enough to handle the features you describe. A complete rewrite of this header processing code would be required, without losing existing features.

For your use case, I would currently recommend using a custom mail filtering script as /usr/bin/sendmail before handing the mails over to msmtp.

marlam avatar Jul 25 '23 15:07 marlam

For your use case, I would currently recommend using a custom mail filtering script as /usr/bin/sendmail before handing the mails over to msmtp.

a wrapper script?, good idea.. i used that technique when i was using ssmtp for a while ... anyway, i am using msmtp in openwrt, so i would prefer not to have to code additional scripts

.... anyway, currently it partially does, like shown in this documentation section: https://marlam.de/msmtp/msmtp.html#Header-handling ... maybe tweaking some few changes in current code :) (first pass: delete headers, second pass: add headers ???).... yes , summarizing, it can be achieved with just 2 new options: --del-header and --add-header (i.e. replacing headers: --del-header From --add-header "From: me <$me>", or --remove-headers 'from*' --add-header from "me <$me>"

maybe in a future, i hope

atesin avatar Jul 27 '23 06:07 atesin

Sorry, I consider this header processing out of scope for msmtp. That looks like a job for a specialized mail filter program.

marlam avatar May 01 '24 11:05 marlam