Class: TMS::EmailMessage

Inherits:
Object
  • Object
show all
Includes:
InstanceResource
Defined in:
lib/tms_client/resource/email_message.rb

Overview

An EmailMessage is used to create and send a email to a collection of EmailRecipient objects. Certain metrics are available after the email is sent, including the collection of recipients who clicked or opened the email.

Examples:

Sending a message

email_message = client.email_messages.build(:subject => "Great news!", :body => "You win! <a href='http://example.com/'>click here</a>.")
email_message.recipients.build(:email => "[email protected]")
email_message.recipients.build(:email => "[email protected]")
email_message.post
email_message.get

Viewing recipients that clicked on a link in the email

email_message.get
email_message.clicked.get
email_message.clicked.collection # => [<#EmailRecipient>,...]

Viewing recipients that opened the email

email_message.get
email_message.opened.get
email_message.opened.collection # => [<#EmailRecipient>,...]

Using macros

email_message = client.email_messages.build(:subject => "Hello [[user]]", 
                                            :body => "Your name is [[name]]",
                                            :macros => {:user => "Sir or Madam", :name => "unknown"})
email_message.recipients.build(:email => "[email protected]", :macros => {:user => "jexample", :name => "Jeff Example"})
email_message.post

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from InstanceResource

included

Instance Attribute Details

#bodyString

The body of the email

Returns:

  • (String)

    the current value of body



38
39
40
# File 'lib/tms_client/resource/email_message.rb', line 38

def body
  @body
end

#click_tracking_enabledBoolean

Whether to track clicks on links in this message. Optional, defaults to true.

Returns:

  • (Boolean)

    the current value of click_tracking_enabled



38
39
40
# File 'lib/tms_client/resource/email_message.rb', line 38

def click_tracking_enabled
  @click_tracking_enabled
end

#created_atObject (readonly)

Returns the value of attribute created_at.



1
2
3
# File 'lib/tms_client/resource/email_message.rb', line 1

def created_at
  @created_at
end

#from_nameString

The name of the person or entity sending the email.

Returns:

  • (String)

    the current value of from_name



38
39
40
# File 'lib/tms_client/resource/email_message.rb', line 38

def from_name
  @from_name
end

#macrosHash

A dictionary of key/value pairs to use in the subject and body as default macros. The message-level macros are used when a recipient has no value for a given macro key.

Returns:

  • (Hash)

    the current value of macros



38
39
40
# File 'lib/tms_client/resource/email_message.rb', line 38

def macros
  @macros
end

#open_tracking_enabledBoolean

Whether to track opens on this message. Optional, defaults to true.

Returns:

  • (Boolean)

    the current value of open_tracking_enabled



38
39
40
# File 'lib/tms_client/resource/email_message.rb', line 38

def open_tracking_enabled
  @open_tracking_enabled
end

#statusObject (readonly)

Returns the value of attribute status.



1
2
3
# File 'lib/tms_client/resource/email_message.rb', line 1

def status
  @status
end

#subjectString

The subject of the email

Returns:

  • (String)

    the current value of subject



38
39
40
# File 'lib/tms_client/resource/email_message.rb', line 38

def subject
  @subject
end

Instance Method Details

#clickedObject

A CollectionResource of EmailRecipients that clicked on at least one link in this email



57
# File 'lib/tms_client/resource/email_message.rb', line 57

collection_attribute :clicked, 'EmailRecipients'

#openedObject

A CollectionResource of EmailRecipients that opened this email



53
# File 'lib/tms_client/resource/email_message.rb', line 53

collection_attribute :opened, 'EmailRecipients'

#recipientsObject

A CollectionResource of EmailRecipients on this email



49
# File 'lib/tms_client/resource/email_message.rb', line 49

collection_attribute :recipients, 'EmailRecipients'