Class: Smtpcom::Sendapi::Email

Inherits:
ApiResource show all
Defined in:
lib/smtpcom/sendapi/email.rb

Constant Summary collapse

MAPPINGS =
{
  subject:          :Subject,
  body_html:        :BodyHtml,
  body_text:        :BodyText,
  template_id:      :TemplateID,
  from:             :From,
  from_name:        :FromName,
  reply_to:         :ReplyTo,
  reply_to_name:    :ReplyToName,
  return_path:      :ReturnPath,
  recipients:       :Recipients,
  recipients_url:   :RecipientsUrl,
  default_recipient_data:     :DefaultRecipientData,
  attachments:      :Attachments,
  campaign:         :Campaign,
  utm_codes:        :UTMCodes,
  email_headers:    :EmailHeaders
}

Instance Method Summary collapse

Methods inherited from ApiResource

#_get, #_get_raw, #_post, build_from_response

Methods included from Request

included

Constructor Details

#initialize(*params) ⇒ Email

Returns a new instance of Email.



24
25
26
27
28
29
# File 'lib/smtpcom/sendapi/email.rb', line 24

def initialize(*params)
  super(*params)
  @recipients = []
  @attachments = []
  @email_headers = []
end

Instance Method Details

#add_attachment(name, content_type, body) ⇒ Object



38
39
40
41
42
43
44
# 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) ⇒ Object



46
47
48
49
50
51
# 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) ⇒ Object



31
32
33
34
35
36
# File 'lib/smtpcom/sendapi/email.rb', line 31

def add_recipient(email, name = nil)
  @recipients << {
    to_address: email,
    to_name:    name
  }
end

#sendObject



53
54
55
# File 'lib/smtpcom/sendapi/email.rb', line 53

def send
  _post '/send', prepare_params, :formatted
end