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.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#html ⇒ Object
Returns the value of attribute html.
-
#list_unsubscribe ⇒ Object
Returns the value of attribute list_unsubscribe.
-
#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_headers(headers) ⇒ Object
- #add_html(html) ⇒ Object
- #add_list_unsubscribe(list_unsubscribe) ⇒ 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.
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/mailersend/email/email.rb', line 26 def initialize(client = Mailersend::Client.new) @client = client @from = {} @recipients = [] @ccs = [] @bcc = [] @reply_to = {} @subject = nil @text = {} @html = {} @variables = [] @personalization = [] = [] = [] @headers = {} @list_unsubscribe = nil @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 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 |
#headers ⇒ Object
Returns the value of attribute headers.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def headers @headers end |
#html ⇒ Object
Returns the value of attribute html.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def html @html end |
#list_unsubscribe ⇒ Object
Returns the value of attribute list_unsubscribe.
8 9 10 |
# File 'lib/mailersend/email/email.rb', line 8 def list_unsubscribe @list_unsubscribe 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 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
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/mailersend/email/email.rb', line 93 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 << { 'content' => base64_encoded, 'filename' => filename, 'disposition' => disposition } end |
#add_bcc(bcc) ⇒ Object
57 58 59 |
# File 'lib/mailersend/email/email.rb', line 57 def add_bcc(bcc) @bcc << bcc end |
#add_cc(ccs) ⇒ Object
53 54 55 |
# File 'lib/mailersend/email/email.rb', line 53 def add_cc(ccs) @ccs << ccs end |
#add_from(from) ⇒ Object
49 50 51 |
# File 'lib/mailersend/email/email.rb', line 49 def add_from(from) @from = from end |
#add_headers(headers) ⇒ Object
109 110 111 |
# File 'lib/mailersend/email/email.rb', line 109 def add_headers(headers) @headers = headers end |
#add_html(html) ⇒ Object
73 74 75 |
# File 'lib/mailersend/email/email.rb', line 73 def add_html(html) @html = html end |
#add_list_unsubscribe(list_unsubscribe) ⇒ Object
113 114 115 |
# File 'lib/mailersend/email/email.rb', line 113 def add_list_unsubscribe(list_unsubscribe) @list_unsubscribe = list_unsubscribe end |
#add_personalization(personalization) ⇒ Object
81 82 83 |
# File 'lib/mailersend/email/email.rb', line 81 def add_personalization(personalization) @personalization << personalization end |
#add_recipients(recipients) ⇒ Object
45 46 47 |
# File 'lib/mailersend/email/email.rb', line 45 def add_recipients(recipients) @recipients << recipients end |
#add_reply_to(reply_to) ⇒ Object
61 62 63 |
# File 'lib/mailersend/email/email.rb', line 61 def add_reply_to(reply_to) @reply_to = reply_to end |
#add_send_at(send_at) ⇒ Object
117 118 119 |
# File 'lib/mailersend/email/email.rb', line 117 def add_send_at(send_at) @send_at = send_at end |
#add_subject(subject) ⇒ Object
65 66 67 |
# File 'lib/mailersend/email/email.rb', line 65 def add_subject(subject) @subject = subject end |
#add_tags(tags) ⇒ Object
89 90 91 |
# File 'lib/mailersend/email/email.rb', line 89 def () << end |
#add_template_id(template_id) ⇒ Object
85 86 87 |
# File 'lib/mailersend/email/email.rb', line 85 def add_template_id(template_id) @template_id = template_id end |
#add_text(text) ⇒ Object
69 70 71 |
# File 'lib/mailersend/email/email.rb', line 69 def add_text(text) @text = text end |
#add_variables(variables) ⇒ Object
77 78 79 |
# File 'lib/mailersend/email/email.rb', line 77 def add_variables(variables) @variables << variables end |
#send ⇒ Object
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/mailersend/email/email.rb', line 121 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' => , 'headers' => @headers, 'list_unsubscribe' => @list_unsubscribe, 'send_at' => @send_at, 'tags' => } client.http.post("#{MAILERSEND_API_URL}/email", json: .delete_if { |_, value| value.to_s.strip == '' || value == [] || value == {} }) end |