Posting image to your tumblr blog using Gmail
well, i'm trying to automate posting my scripts to all by blogs and social profiles, so here is my latest script to send an image with description to tumblr using email posting feature they provide.
#!/usr/bin/env ruby
require 'mail' # gem install mail --no-document
# Credit to :
# http://stackoverflow.com/questions/12884711/how-to-send-email-via-smtp-with-rubys-mail-gem
def ask question
print "#{question} ? : "
$stdin.gets.chomp!
end
# get it from :
# https://www.tumblr.com/settings/blog/yourBlogName
# in the Post by Email section
tumblr_email = 'xxxxxxx@tumblr.com'
email = ask('what is your gmail address')
$options = {
:address => "smtp.gmail.com",
:port => 587,
:domain => email,
:user_name => email,
:password => ask('what is your password'),
:authentication => 'plain',
:enable_starttls_auto => true
}
Mail.defaults do
delivery_method :smtp, $options
end
Mail.deliver do
from $options[:user_name]
to tumblr_email
body ask('write any message associated with the image')
ARGV.each do |file|
add_file file
end
end
puts 'Posting to tumblr succeeded :)'
Written by Emad Elsaid
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#