class Crm::Mailing
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 {liquidmarkup.org/ Liquid template engine} for evaluating mailing content. @api public
Public Instance Methods
Clones a mailing. @example
mailing.clone # => Crm::Mailing
@return [BasicResource] the cloned mailing. @api public
# File lib/crm/mailing.rb, line 28 def clone self.class.new(Core::RestApi.instance.post("#{path}/clone", {})) end
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. @return [self] the updated mailing. @api public
# File lib/crm/mailing.rb, line 107 def release load_attributes(Core::RestApi.instance.post("#{path}/release", {})) end
Renders a preview of the email for the given contact. @example
mailing.html_body # => "<h1>Welcome {{contact.first_name}} {{contact.last_name}}</h1>" contact.email # => "john.doe@example.com" mailing.render_preview(contact) # => { # "email_from" => "Marketing <marketing@example.org>", # "email_reply_to" => "marketing-replyto@example.com", # "email_subject" => "Invitation to exhibition", # "email_to" => "john.doe@example.com", # "text_body" => "Welcome John Doe", # "html_body" => "<h1>Welcome John Doe</h1>" # }
@param render_for_contact_or_id [String, Contact]
the contact for which the email preview is rendered.
@return [Hash{String => String}] the values of the mailing fields evaluated
in the context of the contact.
@api public
# 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
Sends a proof email (personalized for a contact) to the current user (the API user). @example
mailing.send_me_a_proof_email(contact) # => { # "message" => "email sent to api_user@example.com" # }
@param render_for_contact_or_id [String, Contact]
the contact for which the proof email is rendered.
@return [Hash{String => String}] a status report. @api public
# 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
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. @example
contact.email # => "john.doe@example.org" mailing.released_at # => 2014-12-01 12:48:00 +0100 mailing.send_single_email(contact) # => { # "message" => "email sent to john.doe@example.org" # }
@param recipient_contact_or_id [String, Contact]
the contact to send a single email to.
@return [Hash{String => String}] a status report. @api public
# 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
Private Instance Methods
# File lib/crm/mailing.rb, line 113 def extract_id(contact_or_id) if contact_or_id.respond_to?(:id) contact_or_id.id else contact_or_id end end