Apple Mail Export to PDF w/ Headers?
Apple Mail allows for the export of messages to PDF, but can it also preserve or include the SMTP headers? This is important for a number of reasons.
MacBook Pro 15", macOS 10.15
Apple Mail allows for the export of messages to PDF, but can it also preserve or include the SMTP headers? This is important for a number of reasons.
MacBook Pro 15", macOS 10.15
You can create a PDF of a message with full headers using iCloud Mail.
1. In Safari go to icloud.com/mail and sign in with your Apple ID.
2. Double-click a message in the message list to open in a new window.
3. Click the Action pop-up menu in the toolbar, then choose Show Long Headers.
4. Click the Action pop-up menu again, then choose Print. If you get a dialog pop-up "This webpage is trying to print. Do you want to print this webpage?", choose Print.
5. Click the PDF pop-up menu, then choose Save as PDF.
6. Choose a name and location for the PDF file and choose Save.
Be aware that not all elements of a particular message may render properly. The more complicated the message, such as those with graphics or animations, the more likely this will be an issue. Also, you may want to manage page breaks by setting a custom paper size.
You can create a PDF of a message with full headers using iCloud Mail.
1. In Safari go to icloud.com/mail and sign in with your Apple ID.
2. Double-click a message in the message list to open in a new window.
3. Click the Action pop-up menu in the toolbar, then choose Show Long Headers.
4. Click the Action pop-up menu again, then choose Print. If you get a dialog pop-up "This webpage is trying to print. Do you want to print this webpage?", choose Print.
5. Click the PDF pop-up menu, then choose Save as PDF.
6. Choose a name and location for the PDF file and choose Save.
Be aware that not all elements of a particular message may render properly. The more complicated the message, such as those with graphics or animations, the more likely this will be an issue. Also, you may want to manage page breaks by setting a custom paper size.
Enable the display of all headers for a given message.
Highlight a section of the header content using your cursor.
"Select All" will highlight all header content.
Paste into a new RTFD document in Text Edit.
Select all the content below the header (the actual email).
Paste the message under the header material in the same RTFD document.
Export document as PDF.
It's a few clicks for sure, but it will allow everything to be captured in the same format as you see in Mail.
Yes, given sufficient time and programming skills, one can extract selective, message header field content from the individual Mail message, and shove these records into a SQLite3 database. You should look for a local resource to tackle that lengthy and complicated programming exercise. That would be out of scope for what we can provide here with our volunteered time — unless someone else has surplus time on their hands.
Right now, for a given Mail message, I can shove the entire header content (about 1.5 pages of text) into a PDF, and merge that at the front of the exported message's PDF. I even have the code to tell Mail to export the selected message as a PDF. This is a mixture of AppleScript, and Objective-C to get the job done.
All that you get in an exported Mail message PDF is the default headers and mail body text — even when you have displayed All Headers in View menu : Message.
I already have the code here to get just the message's all headers, output that to a temp PDF, and then prepend that PDF content to the beginning of the already exported message PDF content in an output merged PDF.
The nasty business is GUI scripting the message PDF export, and how one assigns a name to that PDF based its account, user, message ID, etc for subsequent identification purposes. The OP needs to further expand the requirements.
And because the OP has stated that they have thousands of messages, the other question is how is the automation told where to access those messages, are they in multiple email accounts, are they to be preselected in groups of messages, and well… the questions just expand.
Forrest Said:
"Apple Mail Export to PDF w/ Headers?: This makes me wonder whether there’s a programmatic way to extract these sections and variables into a database. That sounds like an immensely and over complicated process :-) For example, be able to query based on message ID."
-------
Recommend this to Apple:
Do your Part: I strongly recommend you provide feedback to Apple on this, insisting that they include this as a feature of their Mail app. Recommend that Mail app's Preferences includes a default option to "Show all headers" when exporting an eMail as a PDF Document. Apple may not get back to you directly, but the more they hear of this issue, the more their engineers will know how and what to modify.
VikingOSX Said:
”[...]It is a simple matter to retrieve All Headers from AppleScript for a given message[...]”
———-
So, Compile it:
Well, there’s code out there I tried and it works. I’m modding it to get it line-from-line/server-to-servie/sender-to-recipient takes a bit. I’m working on it on my own time, compiling it
Hopefully I’ll get it to work. I’ll see. You gotta know AppleScript, to get it to work as desired, that’s for sure. :)
Thanks everyone for your input.
The purpose I have is in an official capacity and therefore will require the full SMTP headers, Message-ID, etc., for each message; though, I'd prefer the headers be on their own separate page (for formatting and readability). It may be a challenge doing this.
This makes me wonder whether there’s a programmatic way to extract these sections and variables into a database. That sounds like an immensely and over complicated process :-) For example, be able to query based on message ID.
I should have mentioned that I have thousands of messages to do this with. The purpose I have will require full SMTP headers on at least another page. So this would need to be an automated tool.
You are Welcome.
Forrest Said:
"Apple Mail Export to PDF w/ Headers?: Apple Mail allows for the export of messages to PDF, but can it also preserve or include the SMTP headers? This is important for a number of reasons."
-------
Take a Screenshot & Export it as PDF:
You can always take a screenshot and export it as a PDF document, using: File > Export as PDF...
Go Here: How to Take a Screenshot on your Mac - Apple Support
Forrest Said:
"I should have mentioned that I have thousands of messages to do this with. The purpose I have will require full SMTP headers on at least another page. So this would need to be an automated tool."
-------
For Future Reference... Create and Use an AppleScript as a Rule:
As for the script to use, that I am uncertain of.
Full SMTP Headers may mean different things to different people. Are you referring to what you see when in Apple Mail, you select a message, and then from the View menu, select Message > All Headers, or selected line items from that dump?
It is a simple matter to retrieve All Headers from AppleScript for a given message, but generating a PDF from that header data and prepending it to the PDF exported from Mail for a specific message is more involved. There is no Mail AppleScript Dictionary support to export the original message to PDF either, adding to the complexity, and future fragility of a scripted solution.
Apple Mail Export to PDF w/ Headers?