-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathemail_worker.rb
More file actions
47 lines (38 loc) · 1.07 KB
/
email_worker.rb
File metadata and controls
47 lines (38 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Sample worker that sends an email.
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