Class: Crm::Mailing

Overview

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

Infopark 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, #deleted?, #undelete, #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

#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.



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

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 e-mail 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 e-mail preview is rendered.

Returns:

  • (Hash{String => String})

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



44
45
46
47
48
# File 'lib/crm/mailing.rb', line 44

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 e-mail (personalized for a contact) to the current user (the API user).

Examples:

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

Parameters:

  • render_for_contact_or_id (String, Contact)

    the contact for which the proof e-mail is rendered.

Returns:

  • (Hash{String => String})

    a status report.



60
61
62
63
64
# File 'lib/crm/mailing.rb', line 60

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" => "e-mail sent to [email protected]"
# }

Parameters:

  • recipient_contact_or_id (String, Contact)

    the contact to send a single e-mail to.

Returns:

  • (Hash{String => String})

    a status report.



85
86
87
88
89
# File 'lib/crm/mailing.rb', line 85

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