Class: GovDelivery::TMS::EmailMessage

Inherits:
Object
  • Object
show all
Includes:
InstanceResource
Defined in:
lib/govdelivery/tms/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.

The message-level macros are used when a recipient has no value for a given macro key.

Examples:

Sending a message

email_message = client.email_messages.build(:subject => "Great news!",
                                            :body => "You win! <a href='http://example.com/'>click here</a>.",
                                            :from_email => '[email protected]')
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

Attributes included from InstanceResource

#response

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



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def body
  @body
end

#click_tracking_enabledBoolean

Optional - Whether to track clicks on links in this message. Defaults to true.

Returns:

  • (Boolean)

    the current value of click_tracking_enabled



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def click_tracking_enabled
  @click_tracking_enabled
end

#created_atObject (readonly)

Returns the value of attribute created_at.



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

def created_at
  @created_at
end

#errors_toString

Optional - the email address used for the Errors-To header of this email. Defaults to the account default bounce_email address (which itself defaults to the default from address if not specified).

Returns:

  • (String)

    the current value of errors_to



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def errors_to
  @errors_to
end

#from_emailString

Optional - the email address of the person or entity sending the email. Must be configured in TMS beforehand. Defaults to the account default from address.

Returns:

  • (String)

    the current value of from_email



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def from_email
  @from_email
end

#from_nameString

The name of the person or entity sending the email.

Returns:

  • (String)

    the current value of from_name



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def from_name
  @from_name
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#macrosHash

Optional - A dictionary of key/value pairs to use in the subject and body as default macros.

Returns:

  • (Hash)

    the current value of macros



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def macros
  @macros
end

#open_tracking_enabledBoolean

Optional - Whether to track opens on this message. Defaults to true.

Returns:

  • (Boolean)

    the current value of open_tracking_enabled



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def open_tracking_enabled
  @open_tracking_enabled
end

#reply_toString

Optional - the email address used for the Reply-To header of this email. Defaults to the account default reply_to_email address (which itself defaults to the default from address if not specified).

Returns:

  • (String)

    the current value of reply_to



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def reply_to
  @reply_to
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

#subjectString

The subject of the email.

Returns:

  • (String)

    the current value of subject



43
44
45
# File 'lib/govdelivery/tms/resource/email_message.rb', line 43

def subject
  @subject
end

Instance Method Details

#clickedObject

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



70
# File 'lib/govdelivery/tms/resource/email_message.rb', line 70

collection_attribute :clicked, 'EmailRecipients'

#failedObject

A CollectionResource of EmailRecipients that failed, not neccessarily bounced



78
# File 'lib/govdelivery/tms/resource/email_message.rb', line 78

collection_attribute :failed, 'EmailRecipients'

#openedObject

A CollectionResource of EmailRecipients that opened this email



66
# File 'lib/govdelivery/tms/resource/email_message.rb', line 66

collection_attribute :opened, 'EmailRecipients'

#recipientsObject

A CollectionResource of EmailRecipients on this email



62
# File 'lib/govdelivery/tms/resource/email_message.rb', line 62

collection_attribute :recipients, 'EmailRecipients'

#sentObject

A CollectionResource of EmailRecipients that sent successfully



74
# File 'lib/govdelivery/tms/resource/email_message.rb', line 74

collection_attribute :sent, 'EmailRecipients'