class Smtp2go::Smtp2goClient
Ruby Library for interacting with the smtp2go API
Attributes
headers[R]
Client to handle API interfacing
send_endpoint[R]
Client to handle API interfacing
Public Class Methods
new()
click to toggle source
# File lib/smtp2go/core.rb, line 11 def initialize @api_key = ENV['SMTP2GO_API_KEY'] @headers = HEADERS @send_endpoint = SEND_ENDPOINT raise Smtp2goAPIKeyException unless @api_key end
Public Instance Methods
send(sender:, recipients:, subject:, text: nil, html: nil)
click to toggle source
@param sender [String] the from email address @param recipients [Array <String>] the email address of the recipient(s) @param subject [String] the email subject @param text [String] the email text content (optional if html is passed) @param html [String] the email html content (optional if text is passed) @return [Smtp2goResponse] response object
# File lib/smtp2go/core.rb, line 24 def send(sender:, recipients:, subject:, text: nil, html: nil) raise Smtp2goParameterException unless [html, text].any? payload = { api_key: @api_key, sender: sender, to: recipients, subject: subject, text_body: text, html_body: html } response = HTTParty.post( @send_endpoint, body: JSON.dump(payload), headers: @headers ) Smtp2goResponse.new response end