Class: Mailersend::Email
- Inherits:
-
Object
- Object
- Mailersend::Email
- Defined in:
- lib/mailersend/email/email.rb
Overview
Send an email through MailerSend API
Instance Attribute Summary collapse
-
#attachments ⇒ Object
Returns the value of attribute attachments.
-
#bcc ⇒ Object
Returns the value of attribute bcc.
-
#ccs ⇒ Object
Returns the value of attribute ccs.
-
#client ⇒ Object
Returns the value of attribute client.
-
#from ⇒ Object
Returns the value of attribute from.
-
#html ⇒ Object
Returns the value of attribute html.
-
#personalization ⇒ Object
Returns the value of attribute personalization.
-
#recipients ⇒ Object
Returns the value of attribute recipients.
-
#reply_to ⇒ Object
Returns the value of attribute reply_to.
-
#send_at ⇒ Object
Returns the value of attribute send_at.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
-
#text ⇒ Object
Returns the value of attribute text.
-
#variables ⇒ Object
Returns the value of attribute variables.
Instance Method Summary collapse
- #add_attachment(content:, filename:, disposition:) ⇒ Object
- #add_bcc(bcc) ⇒ Object
- #add_cc(ccs) ⇒ Object
- #add_from(from) ⇒ Object
- #add_html(html) ⇒ Object
- #add_personalization(personalization) ⇒ Object
- #add_recipients(recipients) ⇒ Object
- #add_reply_to(reply_to) ⇒ Object
- #add_send_at(send_at) ⇒ Object
- #add_subject(subject) ⇒ Object
- #add_tags(tags) ⇒ Object
- #add_template_id(template_id) ⇒ Object
- #add_text(text) ⇒ Object
- #add_variables(variables) ⇒ Object
-
#initialize(client = Mailersend::Client.new) ⇒ Email
constructor
A new instance of Email.
- #send ⇒ Object
Constructor Details
#initialize(client = Mailersend::Client.new) ⇒ Email
Returns a new instance of Email.
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/mailersend/email/email.rb', line 24 def initialize(client = Mailersend::Client.new) @client = client @from = {} @recipients = [] @ccs = [] @bcc = [] @reply_to = {} @subject = nil @text = {} @html = {} @variables = [] @personalization = [] @attachments = [] @tags = [] @send_at = send_at end |
Instance Attribute Details
#attachments ⇒ Object
Returns the value of attribute attachments.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def @attachments end |
#bcc ⇒ Object
Returns the value of attribute bcc.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def bcc @bcc end |
#ccs ⇒ Object
Returns the value of attribute ccs.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def ccs @ccs end |
#client ⇒ Object
Returns the value of attribute client.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def client @client end |
#from ⇒ Object
Returns the value of attribute from.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def from @from end |
#html ⇒ Object
Returns the value of attribute html.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def html @html end |
#personalization ⇒ Object
Returns the value of attribute personalization.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def personalization @personalization end |
#recipients ⇒ Object
Returns the value of attribute recipients.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def recipients @recipients end |
#reply_to ⇒ Object
Returns the value of attribute reply_to.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def reply_to @reply_to end |
#send_at ⇒ Object
Returns the value of attribute send_at.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def send_at @send_at end |
#subject ⇒ Object
Returns the value of attribute subject.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def subject @subject end |
#tags ⇒ Object
Returns the value of attribute tags.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def @tags end |
#template_id ⇒ Object
Returns the value of attribute template_id.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def template_id @template_id end |
#text ⇒ Object
Returns the value of attribute text.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def text @text end |
#variables ⇒ Object
Returns the value of attribute variables.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def variables @variables end |
Instance Method Details
#add_attachment(content:, filename:, disposition:) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mailersend/email/email.rb', line 89 def (content:, filename:, disposition:) # content: Can be one of the following: # file_path(String) i.e. 'app/Sample-jpg-image-50kb.jpeg' # Base64 encoded string (String) # Supported types are: https://developers.mailersend.com/api/v1/email.html#supported-file-types content_string = content.to_s if File.readable?(content_string) data = File.read(content_string) base64_encoded = Base64.strict_encode64(data) else base64_encoded = content_string end @attachments << { 'content' => base64_encoded, 'filename' => filename, 'disposition' => disposition } end |
#add_bcc(bcc) ⇒ Object
53 54 55 |
# File 'lib/mailersend/email/email.rb', line 53 def add_bcc(bcc) @bcc << bcc end |
#add_cc(ccs) ⇒ Object
49 50 51 |
# File 'lib/mailersend/email/email.rb', line 49 def add_cc(ccs) @ccs << ccs end |
#add_from(from) ⇒ Object
45 46 47 |
# File 'lib/mailersend/email/email.rb', line 45 def add_from(from) @from = from end |
#add_html(html) ⇒ Object
69 70 71 |
# File 'lib/mailersend/email/email.rb', line 69 def add_html(html) @html = html end |
#add_personalization(personalization) ⇒ Object
77 78 79 |
# File 'lib/mailersend/email/email.rb', line 77 def add_personalization(personalization) @personalization << personalization end |
#add_recipients(recipients) ⇒ Object
41 42 43 |
# File 'lib/mailersend/email/email.rb', line 41 def add_recipients(recipients) @recipients << recipients end |
#add_reply_to(reply_to) ⇒ Object
57 58 59 |
# File 'lib/mailersend/email/email.rb', line 57 def add_reply_to(reply_to) @reply_to = reply_to end |
#add_send_at(send_at) ⇒ Object
105 106 107 |
# File 'lib/mailersend/email/email.rb', line 105 def add_send_at(send_at) @send_at = send_at end |
#add_subject(subject) ⇒ Object
61 62 63 |
# File 'lib/mailersend/email/email.rb', line 61 def add_subject(subject) @subject = subject end |
#add_tags(tags) ⇒ Object
85 86 87 |
# File 'lib/mailersend/email/email.rb', line 85 def () @tags << end |
#add_template_id(template_id) ⇒ Object
81 82 83 |
# File 'lib/mailersend/email/email.rb', line 81 def add_template_id(template_id) @template_id = template_id end |
#add_text(text) ⇒ Object
65 66 67 |
# File 'lib/mailersend/email/email.rb', line 65 def add_text(text) @text = text end |
#add_variables(variables) ⇒ Object
73 74 75 |
# File 'lib/mailersend/email/email.rb', line 73 def add_variables(variables) @variables << variables end |
#send ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/mailersend/email/email.rb', line 109 def send = { 'from' => @from, 'to' => @recipients, 'cc' => @ccs, 'bcc' => @bcc, 'reply_to' => @reply_to, 'subject' => @subject, 'text' => @text, 'html' => @html, 'variables' => @variables, 'personalization' => @personalization, 'template_id' => @template_id, 'attachments' => @attachments, 'send_at' => @send_at, 'tags' => @tags } client.http.post("#{MAILERSEND_API_URL}/email", json: .delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} }) end |