Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Ruby wrapper for "tnef"


Build Status Code Climate

This gem handles e-mail attachments packaged in the Microsoft "application/ms-tnef" MIME type. It's a Ruby wrapper for the tnef converter.

From Wikipedia: "Transport Neutral Encapsulation Format or TNEF is, despite the name, a proprietary E-mail attachment format used by Microsoft Outlook and Microsoft Exchange Server. An attached file with TNEF encoding is most often named winmail.dat or win.dat, and has a MIME type of Application/MS-TNEF."



Tested with Ruby 1.8.7, 1.9.3 and 2.0.0


The binary of tnef is required in a current version, 1.4.6 is ok. Check if this tool already exists on your machine:

tnef --version

It doesn't exist? You can install it:

Mac OS X

Using Homebrew, just do:

brew install tnef

Using MacPorts, just do:

sudo ports install tnef


There are chances that this will work:

apt-get install tnef

Beware: On older Linux distribution, you will get a too old version of tnef, which does not work (e.g. 1.4.3 in Ubuntu Hardy), so you have to compile it by yourself. It's easy:

tar -xzvf tnef-1.4.7.tar.gz
cd tnef-1.4.7
make check
make install


What? I don't think this gem will work on Windows.


gem install tinnef


The gem defines the class TNEF with a class method to convert a given winmail.dat file. Use it with a block like in the following example:

require 'rubygems'
require 'tinnef'

content ='winmail.dat').read
TNEF.convert(content, :command => '/opt/local/bin/tnef') do |temp_file|
  unpacked_content =
  unpacked_filename = File.basename(temp_file.path)"/some/path/#{unpacked_filename}", 'w') do |new_file|

About the naming of this gem

"Tinnef" is a german slang word for "rubbish" or "trash". TNEF => TiNnEF => Tinnef - you know?

Note on Patches/Pull Requests

  • Fork the project.
  • Make your feature addition or bug fix.
  • Add tests for it. This is important so I don't break it in a future version unintentionally.
  • Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
  • Send me a pull request. Bonus points for topic branches.


This code is based on the work by Peter Collingbourne, published as part of the alaveteli project. Thank you for sharing!

Copyright (c) 2010-2013 Georg Ledermann. See MIT-LICENSE for details.

Something went wrong with that request. Please try again.