Thursday, January 28, 2010

Posting to Blogger from Perl

Here is a little snippet that allows you to post to your Blogger blog from Perl:

use Net::SMTP::TLS;
my $mailer = new Net::SMTP::TLS(
    'smtp.gmail.com',    # dont change
    Hello    => 'smtp.gmail.com',         # dont change
    Port     => 587,                      # dont change
    User     => 'your.address@gmail.com', # change to your username
    Password => 'password'                # change to your password
);

# you email address associated with the blog
$mailer->mail('your.address@gmail.com');

# the address to send the post to
$mailer->to('blogid.secretword@blogger.com');
$mailer->data;

# blog post body
$mailer->datasend("Subject: Title of my blog post\n\n")
  ;                                       # keep the trailing \n\n!
$mailer->datasend("The text of my post here\n");

# end blog post
$mailer->dataend;
$mailer->quit;

Let me know how this works for you!