MediaWiki extensions manual
OOjs UI icon advanced-invert.svg
Release status: unmaintained
Implementation Notify
Description Allows emails and their attachments to be sent to a wiki as articles and uploaded files
Author(s) User:Nad
Latest version 2.2.9 (2012-05-16)
License GNU General Public License 2.0 or later
Download see article

The EmailToWiki extension allows emails to be sent to the wiki and imported as an article. Any attachments the email has are uploaded into the wiki and linked to in a section at the end of the email and are uploaded with a unique name so that they don't conflict with other attachments of the same name in other email messages. The title of the articles created for imported emails has a configurable format and the content is created as a template followed by the body-text as shown in the example article content in the section below:


  • Download the following source files from here
  • Put all files in a directory called EmailToWiki in the wikis extensions directory
  • Create an empty directory in EmailToWiki called EmailToWiki.tmp which is writable by the webserver
  • Create an empty file in EmailToWiki called EmailToWiki.log which is writable by the webserver
  • Create configuration in a file called EmailToWiki.conf based on the EmailToWiki.conf.sample file
  • Ensure the configuration file is readable by the Perl script, but not readable by the web-server
  • Call the script on a regular basis, say every five minutes, from crontab as root or a privileged user
  • Include the PHP script from your LocalSettings.php file like usual:
include( "$IP/extensions/EmailToWiki/EmailToWiki.php" );

If using a Windows server you can get Perl from www.activeperl.org and add the execution to you system scheduler from control panel. On Linux you'll already have Perl and you can add the script to your crontab with a line similar to the following which calls the script once every 5 minutes.

*/5 * * * * root /var/www/wiki/extensions/EmailToWiki/EmailToWiki.pl > /dev/null


The Perl script uses Net::POP3, Net::IMAP::Simple, Net::IMAP::Simple::SSL, Email::MIME (at least v1.9), HTTP::Request and LWP::UserAgent. On Debian-based operating systems these dependencies are satisfied via the libwww-perl, libnet-imap-simple-ssl-perl and libemail-mime-perl packages, but on other systems you'll need to figure out what packages you need to do to satisfy these dependencies, or use Perl's own CPAN package manager to install them.


Following is a description of the configuration directives listed in the sample configuration file.

Variable Meaning Default value
$::wiki The URL of the wiki into which the emails should be imported, it must be on the same machine as the Perl script none
$::template The wiki template to wrap the email parameters in 'Email'
$::emailonly Extract just the email address portion of the FROM and TO fields 1
$::html_only If there's HTML formatting in the email don't also add <pre> sections for non-HTML versions of the content 0
$::type The type of email server to collect emails from, either POP3 or IMAP none
$::host The address of the email server (a domain name or IP address) none
$::user The username to login to the email server with (note that if the name includes at @ symbol it must be escaped, e.g. \@ none
$::pass The password to login to the email server with none
$::remove Set to 1 or 0 to specify whether or not to delete messages from the server after processing them 0
$::limit Maximum amount of email message to load (this is measured in lines for POP3 and bytes for IMAP) 1000000
$::format Specifies the format of the wiki article title to generate for an email message. This option is in the form of a string containing tokens which can include \$id, \$date, \$subject, \$to, \$from "Email:\$id (\$subject)"
$::owner This is the Unix user that the web-server runs as so that the Perl script can ensure that the temporary files it creates can be read and removed by the wiki extension 'www-data'

Example templateEdit

The header parameters of the emails that are imported into the wiki are wrapped into a template, the default template is Template:Email, but can be set to something else using the $::template configuration parameter in the *.conf file. Here's an example of what the content of the template might be in the wiki.

{| style="background-color:#eee;border: solid 1px black; padding: 5px"

Example contentEdit

Following is an example of the wikitext generated for imported emails:

 | id      = 4ECED340.9010600@foo.bar
 | date    = Thu, 24 Nov 2011 21:29:04 -0200
 | to      = info@foo.bar
 | from    = Bob <bob@foo.bar>
 | subject = Test message
Body text of the test message

== File attachments ==
*[[File:4ECED340.9010600@foo.bar test1.jpg|test1.jpg]]
*[[File:4ECED340.9010600@foo.bar test2.jpg|test2.jpg]]

See alsoEdit