-
Notifications
You must be signed in to change notification settings - Fork 1
/
sendgrid_example.rb
68 lines (55 loc) · 1.44 KB
/
sendgrid_example.rb
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
$LOAD_PATH << File.dirname(__FILE__) + '/lib'
require 'mlist'
require 'mlist/email_server/smtp'
require 'singleton'
require 'active_record'
SQLITE_DATABASE = "spec/sqlite3.db"
ActiveRecord::Base.silence do
ActiveRecord::Base.configurations = {'test' => {
'adapter' => 'sqlite3',
'database' => SQLITE_DATABASE
}}
ActiveRecord::Base.establish_connection 'test'
load "spec/fixtures/schema.rb"
end
class MailList
include Singleton
include MList::List
def address
'sendgridtest@discuss.memberhub.com'
end
def label
'Sendgrid Testing'
end
def list_id
"sendgrid_testing"
end
def subscribers
[MList::EmailSubscriber.new('something@nomail.net'), MList::EmailSubscriber.new('anotherthing@nomail.net')]
end
end
class ListManager
include MList::Manager
def lists(email)
[MailList.instance]
end
end
list_manager = ListManager.new
mlist_server = MList::Server.new(
:list_manager => list_manager,
:email_server => MList::EmailServer::Smtp.new(
:enable_starttls_auto => true,
:address => "smtp.sendgrid.net",
:port => "587",
:authentication => :plain,
:domain => 'your.domain.com',
:user_name => "smtp@your.domain.com",
:password => "yourpassword"
)
)
post = MList::EmailPost.new({
:subscriber => MailList.instance.subscribers.first,
:subject => "I'm a Program!",
:text => "My simple message that isn't too short"
})
mlist_server.mail_list(MailList.instance).post(post)