Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Initial commit.

  • Loading branch information...
commit 68eb29d6a1b5a66f04b21c252479a70fdaabc7ff 0 parents
@treeder treeder authored
Showing with 51 additions and 0 deletions.
  1. +1 −0  .gitignore
  2. +4 −0 README.markdown
  3. +46 −0 lib/email_worker.rb
1  .gitignore
@@ -0,0 +1 @@
+.idea
4 README.markdown
@@ -0,0 +1,4 @@
+This is a repository of sample workers to be used on [SimpleWorker](http://www.simpleworker.com).
+
+Feel free to copy, steal, take credit for, or whatever you feel like doing with this code. ;)
+
46 lib/email_worker.rb
@@ -0,0 +1,46 @@
+require 'simple_worker'
+require 'mail'
+
+class EmailWorker < SimpleWorker::Base
+
+ attr_accessor :email_domain, :username, :password,
+ :to, :from,
+ :subject, :body
+
+ def run
+ init_mail
+
+ send_mail
+ end
+
+ # Configures smtp settings to send email.
+ def init_mail
+ mail_conf = {:address => "smtp.gmail.com",
+ :port => 587,
+ :domain => email_domain,
+ :user_name => username,
+ :password => password,
+ :authentication => 'plain',
+ :enable_starttls_auto => true}
+ Mail.defaults do
+ # This is the configuration for sending through Gmail
+ delivery_method :smtp, mail_conf
+ end
+ end
+
+ def send_mail
+ mail = Mail.new
+ mail[:from] = from
+ mail[:to] = to
+ mail[:subject] = subject
+ html_part = Mail::Part.new do
+ content_type 'text/html; charset=UTF-8'
+ body(body)
+ end
+ mail.html_part = html_part
+ mail.deliver!
+
+ end
+
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.