-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathbatch.rb
More file actions
115 lines (107 loc) · 2.86 KB
/
batch.rb
File metadata and controls
115 lines (107 loc) · 2.86 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
require 'mailtrap'
require 'base64'
client = Mailtrap::Client.new(api_key: 'your-api-key')
# Set your API credentials as environment variables
# export MAILTRAP_API_KEY='your-api-key'
#
# client = Mailtrap::Client.new
# Bulk sending (@see https://help.mailtrap.io/article/113-sending-streams)
# client = Mailtrap::Client.new(bulk: true)
# Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)
# client = Mailtrap::Client.new(sandbox: true, inbox_id: 12)
# Batch sending with text and html content
batch_base = Mailtrap::Mail.batch_base_from_content(
from: { email: 'mailtrap@demomailtrap.co', name: 'Mailtrap Test' },
subject: 'You are awesome!',
text: 'Congrats for sending test email with Mailtrap!',
html: '<p>Congrats for sending test email with Mailtrap!</p>'
)
File.open('attachment.txt') do |f|
batch_base.add_attachment(content: f, filename: 'attachment.txt')
end
client.send_batch(
batch_base, [
Mailtrap::Mail.from_content(
to: [
{ email: 'john.doe@email.com', name: 'John Doe' }
]
),
Mailtrap::Mail::Base.new(
to: [
{ email: 'jane.doe@email.com', name: 'Jane Doe' }
]
),
{
to: [
{ email: 'david.doe@email.com', name: 'David Doe' }
]
}
]
)
# Batch sending with template
batch_base = Mailtrap::Mail.batch_base_from_template(
from: { email: 'mailtrap@demomailtrap.co', name: 'Mailtrap Test' },
reply_to: { email: 'support@example.com', name: 'Mailtrap Reply-To' },
template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c'
)
client.send_batch(
batch_base, [
Mailtrap::Mail.from_template(
to: [
{ email: 'john.doe@email.com', name: 'John Doe' }
],
template_variables: {
user_name: 'John Doe'
}
),
Mailtrap::Mail::Base.new(
to: [
{ email: 'jane.doe@email.com', name: 'Jane Doe' }
],
template_variables: {
user_name: 'Jane Doe'
}
),
{
to: [
{ email: 'david.doe@email.com', name: 'David Doe' }
],
template_variables: {
user_name: 'David Doe'
}
}
]
)
# You can also pass the request parameters directly
client.send_batch(
{
from: { email: 'mailtrap@demomailtrap.co', name: 'Mailtrap Test' },
reply_to: { email: 'support@example.com', name: 'Mailtrap Reply-To' },
template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c'
}, [
{
to: [
{ email: 'john.doe@email.com', name: 'John Doe' }
],
template_variables: {
user_name: 'John Doe'
}
},
{
to: [
{ email: 'jane.doe@email.com', name: 'Jane Doe' }
],
template_variables: {
user_name: 'Jane Doe'
}
},
{
to: [
{ email: 'david.doe@email.com', name: 'David Doe' }
],
template_variables: {
user_name: 'David Doe'
}
}
]
)