|
12 | 12 | # Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)
|
13 | 13 | # client = Mailtrap::Client.new(sandbox: true, inbox_id: 12)
|
14 | 14 |
|
15 |
| -# Batch sending with Mailtrap::Mail::Base |
16 |
| -mail = Mailtrap::Mail.batch_base_from_content( |
| 15 | +# Batch sending with text and html content |
| 16 | +batch_base = Mailtrap::Mail.batch_base_from_content( |
17 | 17 | from: { email: '[email protected]', name: 'Mailtrap Test' },
|
18 | 18 | subject: 'You are awesome!',
|
19 | 19 | text: 'Congrats for sending test email with Mailtrap!',
|
20 |
| - category: 'Integration Test', |
21 |
| - # attachments: [ |
22 |
| - # { |
23 |
| - # content: Base64.encode64('Attachment content'), # base64 encoded content or IO string |
24 |
| - # filename: 'attachment.txt' |
25 |
| - # } |
26 |
| - # ], |
27 |
| - headers: { |
28 |
| - 'X-MT-Header': 'Custom header' |
29 |
| - }, |
30 |
| - custom_variables: { |
31 |
| - year: 2022 |
32 |
| - } |
| 20 | + html: '<p>Congrats for sending test email with Mailtrap!</p>' |
33 | 21 | )
|
34 | 22 |
|
| 23 | +File.open('attachment.txt') do |f| |
| 24 | + batch_base.add_attachment(content: f, filename: 'attachment.txt') |
| 25 | +end |
| 26 | + |
35 | 27 | client.send_batch(
|
36 |
| - mail, [ |
| 28 | + batch_base, [ |
37 | 29 | Mailtrap::Mail.from_content(
|
38 | 30 | to: [
|
39 |
| - { email: 'your@email.com', name: 'recipient1' } |
| 31 | + { email: 'john.doe@email.com', name: 'John Doe' } |
40 | 32 | ]
|
41 | 33 | ),
|
42 | 34 | Mailtrap::Mail::Base.new(
|
43 | 35 | to: [
|
44 |
| - { email: 'your@email.com', name: 'recipient2' } |
| 36 | + { email: 'jane.doe@email.com', name: 'Jane Doe' } |
45 | 37 | ]
|
46 |
| - ) |
| 38 | + ), |
| 39 | + { |
| 40 | + to: [ |
| 41 | + { email: '[email protected]', name: 'David Doe' } |
| 42 | + ] |
| 43 | + } |
47 | 44 | ]
|
48 | 45 | )
|
49 | 46 |
|
50 |
| -# Batch sending with Mailtrap::Mail::Base |
51 |
| -mail = Mailtrap::Mail.batch_base_from_template( |
| 47 | +# Batch sending with template |
| 48 | +batch_base = Mailtrap::Mail.batch_base_from_template( |
52 | 49 | from: { email: '[email protected]', name: 'Mailtrap Test' },
|
53 | 50 | reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
|
54 |
| - template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c', |
55 |
| - template_variables: { |
56 |
| - 'user_name' => 'John Doe' |
57 |
| - } |
| 51 | + template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c' |
58 | 52 | )
|
59 | 53 |
|
60 | 54 | client.send_batch(
|
61 |
| - mail, [ |
62 |
| - Mailtrap::Mail::Base.new( |
| 55 | + batch_base, [ |
| 56 | + Mailtrap::Mail.from_template( |
63 | 57 | to: [
|
64 |
| - { email: '[email protected]', name: 'recipient1' } |
65 |
| - ] |
| 58 | + { email: '[email protected]', name: 'John Doe' } |
| 59 | + ], |
| 60 | + template_variables: { |
| 61 | + user_name: 'John Doe' |
| 62 | + } |
66 | 63 | ),
|
67 | 64 | Mailtrap::Mail::Base.new(
|
68 | 65 | to: [
|
69 |
| - { email: 'your@email.com', name: 'recipient2' } |
| 66 | + { email: 'jane.doe@email.com', name: 'Jane Doe' } |
70 | 67 | ],
|
71 | 68 | template_variables: {
|
72 |
| - 'user_name' => 'John Doe 1', |
73 |
| - 'user_name2' => 'John Doe 2' |
| 69 | + user_name: 'Jane Doe' |
74 | 70 | }
|
75 |
| - ) |
| 71 | + ), |
| 72 | + { |
| 73 | + to: [ |
| 74 | + { email: '[email protected]', name: 'David Doe' } |
| 75 | + ], |
| 76 | + template_variables: { |
| 77 | + user_name: 'David Doe' |
| 78 | + } |
| 79 | + } |
76 | 80 | ]
|
77 | 81 | )
|
78 | 82 |
|
|
81 | 85 | {
|
82 | 86 | from: { email: '[email protected]', name: 'Mailtrap Test' },
|
83 | 87 | reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
|
84 |
| - template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c', |
85 |
| - template_variables: { |
86 |
| - 'user_name' => 'John Doe' |
| 88 | + template_uuid: '339c8ab0-e73c-4269-984e-0d2446aacf2c' |
| 89 | + }, [ |
| 90 | + { |
| 91 | + to: [ |
| 92 | + { email: '[email protected]', name: 'John Doe' } |
| 93 | + ], |
| 94 | + template_variables: { |
| 95 | + user_name: 'John Doe' |
| 96 | + } |
87 | 97 | },
|
88 |
| - }, |
89 |
| - [ |
90 | 98 | {
|
91 | 99 | to: [
|
92 |
| - { email: '[email protected]', name: 'recipient1' } |
93 |
| - ] |
| 100 | + { email: '[email protected]', name: 'Jane Doe' } |
| 101 | + ], |
| 102 | + template_variables: { |
| 103 | + user_name: 'Jane Doe' |
| 104 | + } |
94 | 105 | },
|
95 | 106 | {
|
96 | 107 | to: [
|
97 |
| - { email: 'your@email.com', name: 'recipient2' } |
| 108 | + { email: 'david.doe@email.com', name: 'David Doe' } |
98 | 109 | ],
|
99 | 110 | template_variables: {
|
100 |
| - 'user_name' => 'John Doe 1', |
101 |
| - 'user_name2' => 'John Doe 2' |
| 111 | + user_name: 'David Doe' |
102 | 112 | }
|
103 | 113 | }
|
104 | 114 | ]
|
|
0 commit comments