Created
June 14, 2012 01:43
-
-
Save amscotti/2927657 to your computer and use it in GitHub Desktop.
Amazon's SQS with SES - http://bit.ly/M5f8DF
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
aws = require ('aws-lib') | |
access_key_id = "<Your access key id>" | |
secret_access_key = "<Your secret access key>" | |
options = { | |
"path" : "<Your queue URL, just the /accountid/queue_name is needed>" | |
} | |
sqs = aws.createSQSClient(access_key_id, secret_access_key, options) | |
outbound = { | |
MessageBody : JSON.stringify({ | |
email: "email@example.com", | |
data: "This is a test msg!" | |
}) | |
} | |
sqs.call "SendMessage", outbound, (err, result) -> | |
if err then console.log "SendMessage error: #{err}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'aws-sdk' | |
require 'json' | |
AWS.config( | |
:access_key_id => "<Your access key id>", | |
:secret_access_key => "<Your secret access key>") | |
ses = AWS::SimpleEmailService.new | |
sqs = AWS::SQS.new | |
url = "<Your queue URL>" | |
while true | |
puts "Checking queue for new work" | |
receive = sqs.queues[url].receive_message() | |
if receive | |
message = JSON.parse(receive.body) | |
puts message | |
ses.send_email( | |
:subject => "A Sample Email", | |
:from => "email@example.com'", | |
:to => message['email'], | |
:body_text => message['data'], | |
:body_html => "<p>#{message['data']}</p>") | |
receive.delete | |
else | |
puts "Sleeping" | |
sleep 5 | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment