class Smtpcom::Sendapi::Email
Constants
- MAPPINGS
Public Class Methods
new(*params)
click to toggle source
Calls superclass method
Smtpcom::Sendapi::ApiResource::new
# File lib/smtpcom/sendapi/email.rb, line 24 def initialize(*params) super(*params) @recipients = [] @attachments = [] @email_headers = [] end
Public Instance Methods
add_attachment(name, content_type, body)
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 38 def add_attachment(name, content_type, body) @attachments << { name: name, content_type: content_type, content: body } end
add_header(name, value)
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 46 def add_header(name, value) @email_headers << { name: name, value: value } end
add_recipient(email, name = nil)
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 31 def add_recipient(email, name = nil) @recipients << { to_address: email, to_name: name } end
send()
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 53 def send _post '/send', prepare_params, :formatted end
Private Instance Methods
prepare_attachments()
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 89 def prepare_attachments @attachments.map do |item| { Name: item[:name], ContentType: item[:content_type], Content: item[:body] } end end
prepare_headers()
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 99 def prepare_headers @email_headers.map do |item| { Name: item[:name], Value: item[:value] } end end
prepare_params()
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 59 def prepare_params { Subject: @subject, BodyHtml: @body_html, BodyText: @body_text, TemplateID: @template_id, From: @from, FromName: @from_name, ReplyTo: @reply_to, ReplyToName: @reply_to_name, ReturnPath: @return_path, Recipients: prepare_recipients, RecipientsUrl: @recipients_url, DefaultRecipientData: @default_recipient_data, Attachments: prepare_attachments, Campaign: @campaign, UTMCodes: @utm_codes, EmailHeaders: prepare_headers } end
prepare_recipients()
click to toggle source
# File lib/smtpcom/sendapi/email.rb, line 80 def prepare_recipients @recipients.map do |item| { ToAddress: item[:to_address], ToName: item[:to_name] } end end