Getting rid of the p7m file extension

The internet has not been helpful this time. I have a zip archive that also has a p7m extension. How can I lose that extension so that I can view the files? Any help is appreciated.

Than you!

Asked By: JaUnCpp


p7m is an encryption format that is often used for email attachments.

I was also not able to find a Linux tool that is able to open that file type after a quick google research. However, there exist some tools for Windows (e.g. Cryptigo p7mViewer) or OSX.

What you could try if you have no access to a computer running Windows/OSX is to install the Windows emulator wine and try to install a Windows viewer in there. I can’t tell you whether this would work, but it is worth a try, if that file is important for you.

Another possible solution could be to install Claws Mail, a mail program for Ubuntu, and this plugin. I am not sure whether that allows you to view those .p7m files with that mail program either, I just got this hint from @Toroidal in the chat.

Answered By: Byte Commander

This is how S/Mime works, it enc/sign a mail, and sends it as an attachment.
Thunderbird and Evolution mail clients are both famous clients that are able to show s/mime attachments.
Also there are good informations on this question How to obtain a S/MIME certificate for e-mail encryption?

Answered By: Mostafa Shahverdy

Create a small shell script like this one:

openssl pkcs7 -inform DER -in "$1" -print_certs -out "$1.pem"
openssl smime -verify -in "$1" -inform der -noverify -signer "$1.pem" -out "$1.pdf" 2>/dev/null
rm "$1.pem"
evince "$1.pdf"
rm "$1.pdf
  1. Make it executable
  2. Select “open with other application”
  3. Choose the small script created above
  4. Done.
Answered By: user3801675

Unfortunately, none of these answers worked for me. The attachment showed up in gmail’s web interface as smime.p7m, and in Thunderbird (which I can now get rid of since it didn’t help) as winmail.dat.

Quickly, as a list of commands, what worked for me was the following (assuming you downloaded the smime.p7m into ~/Downloads):

sudo apt install mpack tnef
cd ~/Downloads
munpack smime.p7m
tnef winmail.dat
ls -lt
rm mail.eml winmail.dat

To determine if this will even help you:

  • just install mpack
  • run munpack on the smime.p7m file
  • A new file should appear (perhaps named winmail.dat). If this is the case, run:

file winmail.dat # or whatever the new filename

  • if “winmail.dat: Transport Neutral Encapsulation Format” appears, install tnef and complete as listed above.
  • if that completes successfully, you should now have your zip archive in the same directory.
  • otherwise, this answer won’t help:

sudo apt remove mpack tnef


FIX Gmail smime.p7m and tnef open mail (with winmail.dat)

How to open winmail.dat files on Ubuntu and Debian Linux

Answered By: rcollins0618

Another solution, inspired from the previous user3801675’s script.

Create a small shell script, in ~/bin directory named like this one:

#set -x
filename="${1##*/}" #extract filename, without path
mkdir "$outdir"
openssl pkcs7 -inform DER -in "$1" -print_certs -out "$outdir/signer.pem"
openssl smime -verify -in "$1" -inform der -noverify -signer  "$outdir/signer.pem" -out "$outfile" 2>/dev/null
xdg-open "$outfile"
#if you don't need extracted file uncoment the following line
#rm "$outdir/signer.pem"; rm "$outfile"; rmdir $outdir
  1. Make it executable chmod +x ~/bin/
  2. From a shell use the command ~/bin/ filename.pdf.p7m


  1. From the file manager select filename.pdf.p7m and using mouse right click choose "open with other application". Then Choose the small script created above.


Usually the received file (attachment) has the extension p7m as in


The proposed script first creates the subdirectory


then extracts the key-file signer.pem and the file filename.pdf removing the extension .p7m.

The two file are saved in the previously created folder.

The extracted file filename.pdf is opened using xdg-open instead of evince, because xdg-open can open all kinds of file using the correct application based on file type.

Nowadays (not sure if this work in the 2015’s version of openssl) one can use just

openssl smime -inform DER -in smime.p7m -verify -out email_body

openssl smime itself is able to get the certificates from the .p7m file if needed.

Answered By: Gerd
Categories: Answers Tags: , , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.