WordPress 中文文档

Blog by Email

From WordPress Chinese

Jump to: navigation, search

目录

WordPress can be configured to use an email account to post to your blog. In order to enable this functionality, you need to set up a dedicated email account, configure WordPress, and configure your web server such that WordPress can check the email account periodically.

You can blog by email using most standard email software programs or a Weblog Client, programs specifically designed to send posts via email.

Note: WordPress 2.2 users are experiencing problems with posting via email with WordPress not recognizing the content of an email. A patch has been issued to fix this problem.

Overview

  1. Set up Writing by Email in Options > Writing in the WordPress Administration Panels.
  2. Create a new email account with the same login name you chose on the Admin Login screen.
  3. Use one of the following options:
    • Open your web browser to view http://yourwebdomain/wordpressinstalldir/wp-mail.php immediately after you send an email to your posting address; this will load the post. You may have to refresh the page.
    • Using the iframe command as described below, insert some short html code into the footer of your WordPress blog, essentially automating the wp-mail.php check you did above; again, you may have to refresh the page to see the new post. THIS IS A GOOD SOLUTION FOR NEW USERS!
    • Use the WP-Cron WP-Mail plugin. (This appears to be obsolete in WP 2.2!)
    • Set up a cron job to periodically view http://yourwebdomain/wordpressinstalldir/wp-mail.php using a command-line HTTP agent such as wget, curl, or GET.
    • Use a .qmail file to call wp-mail.php directly when an email message is delivered. Does your ISP use .qmail?

Setting Up Blog By Email

Step 1 - Setting Things Up: An overview

  1. Login to WordPress with the administration login you use to administer your WordPress blog.
  2. Go to Options > Writing.
  3. Read the instructions under the Writing by Email at the bottom of the page. At the end of these instructions, WordPress will give you three random strings you may use for the login name of the blog-by-email account(postaccount).
  4. You will need to create a new blog-by-email account(postaccount) on your web hosting email server. This is the place where your personal email accounts live. It is not recommended that you use public, free email servers like Yahoo, Hotmail, etc.
    NOTE: Some email servers do not allow numbers-only email accounts or ones starting with a number.
  5. When you are done creating the blog-by-email account(postaccount) on your web hosting email server, return back to Wordpress Options > Writing to fill in the name of the mail server and port number your web hosting provider uses. (If you don't know these, refer to your web hosting provider's FAQ or manual pages. Port number is usually 110.)
  6. Next, enter the login name and password for your new blog-by-email account(postaccount).
    NOTE: The blog-by-email(postaccount) email address should be the complete using user@example.com format, and not just the user name.
  7. Choose the default category for WordPress to assigned posts to when submitted by email.
  8. Click Update Options and you're done!
    Now, send an email to your new blog-by-email account(postaccount). Depending on how you set up Wordpress to process the your new blog-by-email posting, it should work flawlessly.

Step 2 - Creating the Blog-By-Email Account: a reminder

Create the new blog-by-email account with the same name as you specified in the WordPress Admin panel, using the tools your hosting provider provides. Create it with the same password you entered in the WordPress administration section .

Note: It is strongly recommended that you use a "secret" address - that is, an email account name that is very difficult to guess and only known to you. Any email sent to this address will automatically be posted to your blog. WordPress will give you a few good names to use when the time comes to set it up.

Step 3 - Activating Blog-By-Email

The following options set the process through which the email will be captured and released by WordPress into your blog.

Browser Activation

View http://example.com/installdir/wp-mail.php in your web browser immediately after you send an email to your postaccount@example.com account. (Note: You must do this every time you send a new post.)

Automated Browser Activation (Iframes)

An alternative to manual browser activation is to add the following code to the footer of your blog:

<iframe src="http://yourblogdomain/wordpressinstalldir/wp-mail.php" name="mailiframe" width="0" height="0" frameborder="0" scrolling="no" title=""></iframe>

Edit the above line of code so that it refers to the location of your wp-mail.php file. Add this line of code to the footer.php file in the directory for whatever theme you are using (don't include it within an html paragraph).

You may have to refresh your blog to see the new post. THIS IS THE BEST METHOD FOR NEW USERS.

If you're using the Postie plugin for WordPress, then you should use the following iframe code, which will call Postie's check mail commands:

<iframe src="http://yourblogdomain/wordpressinstalldir/wp-content/plugins/postie/get_mail.php?Submit=Run+Postie" name="mailiframe" width="0" height="0" frameborder="0" scrolling="no" title=""> </iframe>

Add this code to your footer, and the next time anyone goes to your blog, your new emails will be automatically posted, so you need to do nothing but send them. You may have to refresh the blog to see the changes.

Plugin Activation

Download, install, and activate the WP-Cron plugin. Activate the included WP-Cron-Mail plugin. It will work in the background without user intervention.

Cron Job Activation

Set up a cron job to 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 authorised 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<br>
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 email, you may be able to use it to call wp-mail.php directly when an email 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.

Email Format

WordPress will use the Subject line of your email for the title of the post, and all body of the email will be used as the content of the post, with common HTML tags stripped. WordPress will file the post under whichever category is selected for "Usual Category" in Step 1, and will use Site Admin as the poster.

Any images and attachments in your email will be posted inline.

Testing

To test your configuration, simply send an email to postaccount@yourmaildomain (or to user@yourmaildomain if you used the .qmail forwarding setup). Then do the following:

  • If you have no automated system set up, simply view http://example.com/installdir/wp-mail.php in your browser. The script should tell you that it found an email, and print details of the post it made. Then view your blog again to see your email posted.
  • If you are using WP-Cron, simply wait fifteen or twenty minutes.
  • If you have a cron job running, wait until the next time it's scheduled to run (or temporarily edit the cron job to make it run sooner). If you run tail -f /var/log/cron in a terminal, you'll be able to see the job create its log entry when it's finished running. When that happens, just view the site in your web browser to see your email posted.

Troubleshooting

Error Message:
Ooops POP3: premature NOOP OK, NOT an RFC 1939 Compliant server

For this error, open wp-includes/class-pop3.php and change this line:

if($this->RFC1939) {

to this:

if(!$this->RFC1939) {

Note the exclamation point.

Error Message: There does not seem to be any new mail

This error is a bit of a misnomer - the test just checks to see if anything was retrieved.

If you're feeling adventuresome open
wp-mail.php
and search for:
 $count = $pop3->login(get_settings('mailserver_login'), get_settings('mailserver_pass'));

Change the lines following it to something like:

  if (0 == $count) :
    echo "There does not seem to be any new mail. <br/>\n";
    echo "count = $count<br/> \n"; 
    echo "$pop3->ERROR \n";
    exit;
  endif;

You'll then be presented with a more informative message.

One possibility (was in my case) is the mail server refuses connections that attempt to provide an unencrypted password - like POP3. If your webserver and email server are on the same physical computer you can specify localhost or 127.0.0.1 as the mail server. That traffic is assumed to be OK without encryption because it never traveled across the network.

Extensions and Add-ons

There are several add-ons and hacks which will extend the capabilities of blogging by email with WordPress. Some of these may involve changing the core files, so do it carefully and make backups.

Enhanced Functionality Hack

One replacement file for the original wp-mail.php file has been created:

  • Postie supports posting to categories, automatic removal of email signatures, POP3/IMAL (+SSL) and more.

Hack Email Format

The following enhancements may be made to your wp-mail.php so your email will be translated into metadata for your post:

Sender's email address 
The enhanced wp-mail.php looks up the email address you send from in its user database. If there is a match with any user there, it files the post under that user. If there is no match, it drops the email and does not create a post in the blog. (Great for security and spam prevention.) It is set by the From:
Subject line 
If [n] is present anywhere in the subject line of your email, the email will be filed under the category numbered n. Otherwise, it will be posted under whichever category is selected for "Usual Category" in Step 1. Example: [1] This is a Test! would be posted as "This is a Test!", filed under General.Template:Copyedit
Views
用户
导航
WordPress
工具