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

Posted on Dec 24, 2019 9:44 AM

Reply
Question marked as Top-ranking reply

Posted on Dec 25, 2019 6:47 AM

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.

14 replies
Question marked as Top-ranking reply

Dec 25, 2019 6:47 AM in response to Forrest

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.

Dec 24, 2019 12:08 PM in response to Forrest

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.

Dec 25, 2019 4:36 PM in response to Forrest

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.



Dec 25, 2019 9:46 AM in response to TheLittles

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.

Dec 25, 2019 5:02 PM in response to Forrest

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.

  1. Go Here: Feedback - Mail - Apple
  2. Select: "Feature Request" for the "Feedback Type"
  3. Proceed from there as necessary.

Dec 25, 2019 9:34 AM in response to VikingOSX

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. :)

Dec 24, 2019 11:28 AM in response to Forrest

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

Dec 24, 2019 11:07 PM in response to Forrest


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:


  1. Go To: Mail > Preferences > Rules > Add Rules
  2. Where it Reads: "Perform the Following Action..." Select: "Run AppleScript".
  3. To Create an AppleScript: use ScriptEditor, found in the Utilities folder of the Applications folder
  4. Add the AppleScript to: com.apple.mail


As for the script to use, that I am uncertain of.

Dec 25, 2019 2:07 AM in response to Forrest

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.



This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Apple Mail Export to PDF w/ Headers?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.