I am trying to modify a script which grabs data from a database and puts it into the message of an email which is then sent out using mailx. What I need to do is grab the date which is in the first line of the message body and use that as the date in the header. These emails get ingested by another system and the only way to search these emails properly by date is to include the date from the body as the header date. We sometimes run into an issue where the script does not run and we manually re run the emails. As a result, they get stamped with the current date/time rather than when the data was originally created. I know how to put the date in the message body and/or the subject, but I really need to just modify the header date.
If you stored the extracted database data in a file before you send it per mail you can use something along
mailx -s "$( sed 1q yourfile )" user@domain < yourfile