IPB

Welcome Guest ( Log In | Register )

Movable Type

We're moving to movabletype.org!

At long last, we're moving to forums powered by, well, Movable Type itself. You'll want to bookmark http://forums.movabletype.org/ for future reference, and in the meantime you can view these old forums as a read-only archive of past posts. Thanks for being part of the community!

 
Reply to this topicStart new topic
> Email To Blog - Working!, I know. I can't believe it either.
iki
post Jul 22 2007, 12:27 PM
Post #1





Group: Members
Posts: 169
Joined: 9-March 03
Member No.: 8,761



Nothing fancy - just plain text email to plain text entry. No categories, no tags, just a subject (post title) and text (entry body). I'd love it if someone who knew something more than I do could make it do categories, but that's a little beyond my capabilities. Sorry. smile.gif

I'm using Ian Barton's pop3-to-blog.pl script. I tested it today in MT 3.15, 3.17, 3.2, 3.31, and MT4 Beta 7. It works in all of them. And it works with only the one script - no need to run periodic tasks, or use mt-rebuild, or anything else.

I did clean installs of all those versions of MT, and each time I updated the script with the correct info, sent an email, and POOF there it was on the blog. No rebuilding. No fuss, no muss. ohmy.gif I'm all agog. (I would have tried it in 3.33 and 3.35, but frankly I was getting tired of installing MT by 3.31 and skipped right to MT4.)

Disclaimer: I'm not a programmer. I don't speak Perl, I speak PHP so I'm not even sure what this thing is doing. I wouldn't know an API if it bit me in the butt, and I don't write plugins. Nonetheless, this is what works on MY host (Total Choice), on MY domain (I was using space off my reseller account for this test), with an email account that I set up myself. This is what works with a clean, completely untouched installation of MT. I'm not saying it will work for you, but I wanted to put it out here and let people know that it DOES work with all these versions of MT.

Here is the script:

CODE
#!/usr/local/bin/perl


# Create Blog entries from a POP3 message.
# Messages posted to Blog are deleted.
# based on the script by
# Charlie Reitsma, January 2003, Denison University
# Updated by Ian Barton, February 2003.
# http://www.ian-barton.com
# Email: ibarton@thecottage.org

# Read a POP3 message.

# You need this line if Net::Blog and Mail::POP3Client
# are not installed on your ISP's server.
# use lib qw(/path to Net::Blog and Mail::POP3Client libs);

use Net::Blogger;
use File::Temp qw / :mktemp /;
use File::Basename;
use Mail::Address;
use Mail::POP3Client;


$Subject = "";
$From = "";
$Sender = "";
$User = "";

# You need to update these variable to suit your setup.
$blogsite = "http://www.yoursite.com/mtdir/mt-xmlrpc.cgi";  
$blogid = "1";  ## ID of the Blog you wan't to post to.
$bloguser = "yourusername";  
$blogpass = "yourpassword";
$popsite = "mail.yoursite.com";
$popuser = "emailuser+yoursite.com";
$poppass = "pop3password";


# Log activity.
open(LOGFILE, ">>poplog.log");

# List of usernames allowed to post .
# This should be the part before the @ symbol in your
# Email address.
%allowed = ('youremailusername',1,'anotheruser',1,'someotherperson',1);

# Prepare the blog .
# If you are not using MovableType
# change this.
$blg = Net::Blogger->new(engine=>'movabletype');
$blg->Proxy($blogsite);
$blg->BlogId($blogid);
$blg->Username($bloguser);
$blg->Password($blogpass);

# Open the POP account
$pop = new Mail::POP3Client( USER     => $popuser,
                   PASSWORD => $poppass,
                   HOST     => $popsite );


#Iterate through all the messages.
for( $i = 1; $i <= $pop->Count(); $i++ ) {
    foreach( $pop->Head( $i ) ) {
      # Get the message headers looking for
      # For: and Subject:.
      if (/^From:\s+/i) {
    $From = $_;
    # Get the user name from the From: line
    my @addrs = Mail::Address->parse($From);
    $User = @addrs[0]->user;
    
      }  

      if (/^Subject:\s+/i) {
        $Subject = $_;
        # Chop of Subject:
        $Subject = substr($Subject, 9);
      }  

      
    }
    $Body = $pop->Body($i);
    if ($allowed{$User}) { # only accept messages from allowed senders
        if ($Body) {
          $id = $blg->metaWeblog()->newPost(title=>$Subject,description=>$Body,publish=>1);
          if ($id) {
        # Timestamp for the log.
        ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
        $year = sprintf("%02d", $year % 100); # Make 2 digit year.
        $mon += 1; #month is 0 based i.e. 0 = Jan, 11 = Dec

        printf(LOGFILE "%02d-%02d-%02d %s %02d:%02d:%02d ->Posting message" ,
                   $mday,$mon,$year,$Day[$wday],$hour,$min,$sec);
                print(LOGFILE "\n");  
        
        print LOGFILE "$Subject \n";
        print LOGFILE "Message posted $i.\n";
        print "Message posted.\n", $Subject;
        $pop->Delete($i);
        print LOGFILE "Message MsgID: $i deleted. \n";
        
          } else {
        # print message that cannot be blogged
           print LOGFILE "Could not blog message:\n",$Subject,"\n";
            
          }
        }
    } else {
    
      print LOGFILE "Attempt to post message from invalid sender: $From \n";
    }

    
}

# Close POP box..
$pop->Close();
print LOGFILE "Finished processing mail. \n";
close(LOGFILE);


Copy the preceding code and paste it into a blank text file, then save it as "pop3-to-blog.pl" and fill in the options.

Let's take the options a couple at a time:


CODE
$blogsite = "http://www.yoursite.com/mtdir/mt-xmlrpc.cgi";  

This is the URL to the mt-xmlrpc.cgi file. It's usually in the root directory of your MT installation. Wherever mt.cgi lives, there this file will also live.


CODE
$blogid = "1";  ## ID of the Blog you wan't to post to.

This is the number of the blog you want to post the emails to. You find it (pre MT4, this is) by hovering over the title of the blog, or looking at the URL in the address bar when you're writing a post. It's going to say something like "http://www.yoursite.com/cms/mt.cgi?__mode=menu&blog_id=1". See that blog_id number? That's it.



CODE
$bloguser = "Iki";  

Your username... the name you type to log in to MT.



CODE
$blogpass = "yourpassword";

The password you type to login to MT. In earlier versions - pre MT3.2, there was just the one password. After, there's a "web services" password or some such thing. The first thing I do is go into my user profile and change the web services password to the same thing as my log in password. I'm sure it's not secure, or smart, or whatever - but I'm not concerned with security, I just want to be able to email to my dang blog. There used to be caveats along with this, that you should create a second author in your blog with a different password than your default stuff - an indentity strictly for emailing to the blog. You're free to do that if you want to.


CODE
$popsite = "mail.yoursite.com";

This is the host where email account you want the script to check is at. I was using a domain of mine, freeformrpg.com. The pop3 server for that domain is "mail.freeformrpg.com" so that's what I put here.



CODE
$popuser = "emailuser+yoursite.com";

The email account I created was "mobile@freeformrpg.com". On my host, you can't just put "mobile" for your popuser name - you have to lay it out like "mobile+freeformrpg.com". Your mileage may vary. Try it with just the username... with the entire addresss... or with a plus sign. The plus sign is what works for me, so that's what I put here.



CODE
$poppass = "pop3password";

Simple - the password to access that email account.



CODE
# List of usernames allowed to post .
# This should be the part before the @ symbol in your
# Email address.
%allowed = ('youremailusername',1,'anotheruser',1,'someotherperson',1);

This is the email you are going to use to SEND posts to your blog. This makes it so just any Joe Blow can't email posts to your blog - the emails have to originate from an email address with the username listed here. I use one for my gmail account and one for my work account, so I can email to my blog from work or from my cell or any other computer where I can access my gmail. I'm sorry to say I don't know what those number "1"'s are for.



So - you've got your pop3-to-blog.pl file all edited with your own information. You've created your email account on the server (I don't think you even need it to be on the same server as your MT installation, but I haven't tried that so I'm not sure.) and you've verified that you can indeed receive email at that address. Now you need to FTP that pl file to your server. I keep mine outside the public_html directory, in a directory I created called "cronjobs". (Very original, I know.) The file doesn't need any special permissions - whatever it gets when you upload it is fine.

Now, set up a cron job. I have CPanel, so I go to Cron Jobs, then Advanced (Unix), and in the spaces I put this:

QUOTE
*/30 * * * * /usr/bin/perl /home/myuserspace/cronjobs/pop3-to-blog.pl


That makes the cron run every 30 minutes: be kind to your host and don't run that script every 5 minutes - especially if you're not going to be posting every 5 minutes.

Troubleshooting: You need these modules installed on your server for this to work. Generally, this isn't something you do yourself - open a help ticket with your host and ask them if these are installed. If they aren't ask them to install them.

Mail::POP3Client
Net::Blogger
File::Temp
File::Basename
Mail::Address

This script won't work without these libraries.

So there you go. Please don't ask me for more or better functionality - I can't help you. I also can't help you make it work on YOUR server. But hopefully this post will be of some use to some people out there who want to be able to email to their MT blogs.

This post has been edited by iki: Nov 27 2007, 10:36 AM


--------------------
"You know, some days even my lucky rocketship underpants don't help." - Calvin, Calvin and Hobbes
Go to the top of the page
 
+Quote Post
BassoonStud
post Oct 7 2007, 12:28 PM
Post #2





Group: Members
Posts: 35
Joined: 19-October 05
Member No.: 33,420



QUOTE (iki @ Jul 22 2007, 01:27 PM) *
Net::Blog
Mail::POP3Client
Net::Blogger
File::Temp
File::Basename
Mail::Address

This script won't work without these libraries.



I'm attempting to add your script to one of my sites. So far, so good except neither I nor my ISP can find the following model:

Net::Blog


Do you know where I can find it?

Thanks.
Go to the top of the page
 
+Quote Post
iki
post Nov 27 2007, 10:35 AM
Post #3





Group: Members
Posts: 169
Joined: 9-March 03
Member No.: 8,761



I think that's another example of how retarded my ex-host is. It was listed in one of the scripts I was trying to make work, and asked them to install it, and they just went on and said they did it. Which is impossible since now that I'm looking for it, I don't think it exists either. ohmy.gif

Sorry about that, I'll edit the original post. Thanks for the heads up!

-Iki


--------------------
"You know, some days even my lucky rocketship underpants don't help." - Calvin, Calvin and Hobbes
Go to the top of the page
 
+Quote Post
iki
post Jan 3 2008, 08:01 AM
Post #4





Group: Members
Posts: 169
Joined: 9-March 03
Member No.: 8,761



This is for Miles, who emailed me from this board - I can't email you back because the message came from the forums, not from you.

I don't think it matters where you put the script - cgi-bin should be ok.

Please let me know if you get it working for you. smile.gif


--------------------
"You know, some days even my lucky rocketship underpants don't help." - Calvin, Calvin and Hobbes
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



Lo-Fi Version Time is now: 02.09.10 - 10:44 PM