Codex

Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Post to your blog using email

WordPress can be configured to use e-mail to post to a blog through the use of plugins.

Using Plugins

Configure WordPress Install

The built-in WordPress functionality is deprecated and will be removed in an upcoming release. Please use one of the plugins listed above, instead. For installation and configuration instructions, refer to the documentation for these plugins.

Customizing How WordPress Checks for New Mail

Most plugins should manage this for you!

Calling wp-mail.php directly will be deprecated in an upcoming WordPress release, so the old methods of adding code to your footer or manually visiting wp-mail.php are no longer recommended.

Instead, use some method to trigger the action wp-mail.php. If you're using a plugin that doesn't allow you to customize this, you can try the suggestions below.

Action-based functions.php Activation

You can add an action to your active theme's functions.php file. This will check for mail every 15 minutes and does not add any HTML to your theme.

add_action( 'shutdown', 'retrieve_post_via_mail' );
function retrieve_post_via_mail() {
	flush(); // Display the page before the mail fetching begins
	if ( get_transient( 'retrieve_post_via_mail' ) ) { 
		return; // The mail has been checked recently; don't check again
	} else { // The mail has not been checked in more than 15 minutes
		do_action( 'wp-mail.php' );
		set_transient( 'retrieve_post_via_mail', 1, 15 * MINUTE_IN_SECONDS ); // check again in 15 minutes.
	}
}

This method is good for users who would like to avoid using cron jobs, which are configured on the server. Unlike cron jobs, this process will only run when pages on the blog are loaded. Cron jobs run independent of site traffic.

Cron Job Activation

Set up a UNIX cron job to have your blog periodically view http://example.com/installdir/wp-mail.php using a command-line HTTP agent like wget, curl or GET. The command to execute will look like:

wget -N http://example.com/installdir/wp-mail.php

If you use a different program than wget, substitute that program and its arguments for wget in this line.

Note: Another possibility is to run "php /full/path/to/wp-mail.php" in a cronjob. This will run the php-script using php, without the need for an extra program to run. (You are more likely authorized to run php than wget.)

For more information about setting up a cron job, see:

Note to Windows Users: There are similar programs to cron available if your host runs Windows. For example, VisualCron, Cron for Windows and pycron. Consult these projects' documentation for further information.

Procmail Activation

If your server uses procmail, a simple .procmailrc in the blogmailaccounts home directory will be sufficient:

Shell=/bin/sh
MAILDIR=$HOME/.maildir/
DEFAULT=$MAILDIR
:0
{
:0Wc
./
:0
| wget -N http://example.com/installdir/wp-mail.php
}

This could be more specific, such as capturing certain subject expressions. Check procmail for more information.

.qmail Activation

If your server uses qmail to process e-mail, you may be able to use it to call wp-mail.php whenever an e-mail message is delivered. To do this, first create a small shell script to call wp-mail.php. You could call the file wp-mail:

#!/bin/sh
/bin/sh -c "sleep 5; /path/to/php /path/to/your/blog/wp-mail.php > /dev/null" &

The sleep command causes a 5-second delay to allow qmail to finish processing the message before wp-mail.php is called. Note that the ampersand on the end of the line is required. The above script should go in your root directory, and the execute bit should be set (chmod 700). For debugging purposes, you could change /dev/null to a filename to save the output generated by wp-mail.php.

Then all you need to do create/modify the appropriate .qmail file to call your shell script. Add the following line to the .qmail file for your mailbox name:

|/path/to/your/root/directory/wp-mail

See your ISP's documentation for use of .qmail files. Naming conventions may vary for different ISPs.


References