Class: Crm::Mailing

Overview

The purpose of a JustRelate WebCRM mailing is to send an email, e.g. a newsletter, to several recipients. The emails will be sent to the members of the contact collection associated with the mailing (mailing.collection_id).

JustRelate WebCRM uses the / Liquid template engine for evaluating mailing content.

Instance Method Summary collapse

Methods included from Core::Mixins::Findable::ClassMethods

find

Methods included from Core::Mixins::Modifiable::ClassMethods

create

Methods included from Core::Mixins::Searchable::ClassMethods

all, first, query, search_configurator, where, where_not

Methods included from Core::Mixins::Inspectable

#inspect

Methods included from Core::Mixins::ChangeLoggable

#changes

Methods included from Core::Mixins::Modifiable

#delete, #update

Methods inherited from Core::BasicResource

base_type, #eql?, #id, path, #path, #reload, resource_name, #type

Methods included from Core::Mixins::AttributeProvider

#[], #attributes, #initialize, #method_missing, #methods, #raw, #respond_to_missing?

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Crm::Core::Mixins::AttributeProvider

Instance Method Details

#cloneBasicResource

Clones a mailing.

Examples:

mailing.clone
# => Crm::Mailing

Returns:

  • (BasicResource)

    the cloned mailing.



28
29
30
# File 'lib/crm/mailing.rb', line 28

def clone
  self.class.new(Core::RestApi.instance.post("#{path}/clone", {}))
end

#releaseself

Releases this mailing.

Sends the mailing to all recipients, marks the mailing as released (released_at, released_by), and also sets planned_release_at to now.

Returns:

  • (self)

    the updated mailing.



107
108
109
# File 'lib/crm/mailing.rb', line 107

def release
  load_attributes(Core::RestApi.instance.post("#{path}/release", {}))
end

#render_preview(render_for_contact_or_id) ⇒ Hash{String => String}

Renders a preview of the email for the given contact.

Examples:

mailing.html_body
# => "<h1>Welcome {{contact.first_name}} {{contact.last_name}}</h1>"

contact.email
# => "[email protected]"

mailing.render_preview(contact)
# => {
#  "email_from" => "Marketing <[email protected]>",
#  "email_reply_to" => "[email protected]",
#  "email_subject" => "Invitation to exhibition",
#  "email_to" => "[email protected]",
#  "text_body" => "Welcome John Doe",
#  "html_body" => "<h1>Welcome John Doe</h1>"
# }

Parameters:

  • render_for_contact_or_id (String, Contact)

    the contact for which the email preview is rendered.

Returns:

  • (Hash{String => String})

    the values of the mailing fields evaluated in the context of the contact.



54
55
56
57
58
# File 'lib/crm/mailing.rb', line 54

def render_preview(render_for_contact_or_id)
  Core::RestApi.instance.post("#{path}/render_preview", {
    'render_for_contact_id' => extract_id(render_for_contact_or_id)
  })
end

#send_me_a_proof_email(render_for_contact_or_id) ⇒ Hash{String => String}

Sends a proof email (personalized for a contact) to the current user (the API user).

Examples:

mailing.send_me_a_proof_email(contact)
# => {
#   "message" => "email sent to [email protected]"
# }

Parameters:

  • render_for_contact_or_id (String, Contact)

    the contact for which the proof email is rendered.

Returns:

  • (Hash{String => String})

    a status report.



70
71
72
73
74
# File 'lib/crm/mailing.rb', line 70

def send_me_a_proof_email(render_for_contact_or_id)
  Core::RestApi.instance.post("#{path}/send_me_a_proof_email", {
    'render_for_contact_id' => extract_id(render_for_contact_or_id)
  })
end

#send_single_email(recipient_contact_or_id) ⇒ Hash{String => String}

Sends this mailing to a single contact.

Use case: If someone registers for a newsletter, you can send them the most recent issue that has already been released.

Examples:

contact.email
# => "[email protected]"

mailing.released_at
# => 2014-12-01 12:48:00 +0100

mailing.send_single_email(contact)
# => {
#   "message" => "email sent to [email protected]"
# }

Parameters:

  • recipient_contact_or_id (String, Contact)

    the contact to send a single email to.

Returns:

  • (Hash{String => String})

    a status report.



95
96
97
98
99
# File 'lib/crm/mailing.rb', line 95

def send_single_email(recipient_contact_or_id)
  Core::RestApi.instance.post("#{path}/send_single_email", {
    'recipient_contact_id' => extract_id(recipient_contact_or_id)
  })
end