Skip to content

Commit

Permalink
Initial take on sending an email from Jekyll
Browse files Browse the repository at this point in the history
  • Loading branch information
mwunsch committed Oct 7, 2015
1 parent 70c9e07 commit a402cbb
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
1 change: 1 addition & 0 deletions Gemfile
@@ -1,3 +1,4 @@
source "https://rubygems.org"

gem 'github-pages'
gem 'netrc'
2 changes: 2 additions & 0 deletions Gemfile.lock
Expand Up @@ -95,6 +95,7 @@ GEM
mini_portile (0.6.2)
minitest (5.7.0)
net-dns (0.8.0)
netrc (0.10.3)
nokogiri (1.6.6.2)
mini_portile (~> 0.6.0)
parslet (1.5.0)
Expand Down Expand Up @@ -126,6 +127,7 @@ PLATFORMS

DEPENDENCIES
github-pages
netrc

BUNDLED WITH
1.10.3
31 changes: 31 additions & 0 deletions _plugins/email_newsletter.rb
@@ -0,0 +1,31 @@
require 'jekyll'
require 'net/smtp'
require 'netrc'
require 'pp'

class EmailNewsletter < Jekyll::Generator
SMTP_SERVER = "mail.messagingengine.com"
NETRC_PATH = File.expand_path("~/.authinfo")

def generate(site)
netrc = Netrc.read(NETRC_PATH)[SMTP_SERVER]
if netrc.nil?
warn("Missing credentials for #{SMTP_SERVER} in #{NETRC_PATH}. Will not attempt to email newsletter.")
return nil
end
user, pass = netrc
smtp = Net::SMTP.new("mail.messagingengine.com", 465)
smtp.enable_tls
letters = site.categories["tinyletter"]
letters.select(&:published?).each do |post|
smtp.start("markwunsch.com", user, pass, :plain) do |mail|
# This is the scaffolding for determining how to send an email over
# smtp in a similar fashion to publishing to tumblr.
# We select all the non-published letters. Similarly to the tumblr_id
# field, we identify published letters by having a message_id.
# We generate message_ids, email them, and abort on successful sends.
# Easy peasy.
end
end
end
end
5 changes: 5 additions & 0 deletions tinyletter/_drafts/testing.md
@@ -0,0 +1,5 @@
---
title: "hi?"
---

Testing testing testing

0 comments on commit a402cbb

Please sign in to comment.