-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfull.rb
49 lines (41 loc) · 1.44 KB
/
full.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
require 'mailtrap'
require 'base64'
mail = Mailtrap::Mail::Base.new(
from: { email: '[email protected]', name: 'Mailtrap Test' },
to: [
{ email: '[email protected]', name: 'Your name' }
],
reply_to: { email: '[email protected]', name: 'Mailtrap Reply-To' },
cc: [
{ email: '[email protected]', name: 'Copy To' }
],
bcc: [
{ email: '[email protected]', name: 'Hidden Recipient' }
],
subject: 'You are awesome!',
text: 'Congrats for sending test email with Mailtrap!',
category: 'Integration Test',
attachments: [
{
content: Base64.encode64('Attachment content'), # base64 encoded content or IO string
filename: 'attachment.txt'
}
],
headers: {
'X-MT-Header': 'Custom header'
},
custom_variables: {
year: 2022
}
)
data = File.read('/path/to/image.jpg')
encoded = Base64.encode64(data).gsub("\n", '')
mail.add_attachment(content: encoded, filename: 'image.png')
client = Mailtrap::Client.new(api_key: 'your-api-key')
# Custom host / port
# client = Mailtrap::Client.new(api_key: 'your-api-key', api_host: 'alternative.host.mailtrap.io', api_port: 8080)
# Bulk sending (@see https://help.mailtrap.io/article/113-sending-streams)
# client = Mailtrap::Client.new(api_key: 'your-api-key', bulk: true)
# Sandbox sending (@see https://help.mailtrap.io/article/109-getting-started-with-mailtrap-email-testing)
# client = Mailtrap::Client.new(api_key: 'your-api-key', sandbox: true, inbox_id: 12)
client.send(mail)