Owns creation, sending and tracking of EmailItems, and is reached from server-side JS as services.emailManager. A developer starts a new email with emailBuilder, which returns an EmailItemBuilder to set the recipient, sender, subject and body before building and sending it. The manager also finds recipients and jobs for group and automated emails, tracks delivery, read and conversion status for individual items, and reports role checks for who may administer, edit or send email and view its recipients. It starts and stops the underlying mail server, and its background acknowledgement queue, as part of the application lifecycle.

Group: Managers

Implements: StartableService


Properties

PropertyReturnsDescription
automationEmailLimitIntegerThe maximum number of recipients allowed for a single automated email, for the current tenant organisation.
emailTemplatesListFinds the group email jobs stored as templates for the current tenant organisation. This is a database lookup.
groupEmailLimitIntegerThe maximum number of recipients allowed for a single group email, as configured for the email app on the current tenant.

Methods

findRecipients(BaseEmailJob job) · findRecipients(BaseEmailJob job, JobStatus jobStatus) · findByDate(Date start, Date finish) · findGroupEmailsByOrg() · getGroupEmailLimit() · emailBuilder() · getEmailTemplates() · emailSearch(String q, Long funnelId, BaseEmailJob job, Date startDate, Date endDate, Integer startRow, Integer maxSize) · findJobsByDate(Date startDate, Date finish) · emailStatsDb(BaseEmailJob j, Date startDate, Date finish) · emailStats(BaseEmailJob j, Date startDate, Date endDate) · getEmailContent(EmailItem emailItem) · parseEmailAddress(String emailAddress) · emailItemUpdated(EmailItem emailItem) · updateEmailComplete(EmailItem emailItem, boolean fireEvent) · updateEmailFailed(EmailItem emailItem, boolean fireEvent) · updateEmailOpened(EmailItem emailItem, boolean fireEvent) · updateEmailConverted(EmailItem emailItem, boolean fireEvent) · createSendAttempt(EmailItem emailItem) · sendAttemptUpdated(EmailSendAttempt esa) · getAutomationEmailLimit() · getAutomationEmailLimit(Organisation adminOrg) · createEmailTemplate(String templateName, String title, String subject, String emailBody, Website website) · findGroupEmailType(String type) · addGroupRecipient(BaseEmailJob emailJob, Group group, boolean exclusion) · removeGroupRecipient(BaseEmailJob emailJob, Group group, boolean exclusion) · addOrganisationRecipient(BaseEmailJob emailJob, Organisation organisation, boolean exclusion) · removeOrganisationRecipient(BaseEmailJob emailJob, Organisation organisation, boolean exclusion) · findBaseEmailJobById(Long id) · isEmailAdministrator(Profile profile) · isEmailEditor(Profile profile) · isEmailSender(Profile profile) · canViewRecipients(Profile profile)

findRecipients(BaseEmailJob job)

Returns: List<ExtProfileBean>

Finds the profiles who will receive the given email job, after applying group or scheduled recipient rules and filtering out any without an email address. This is a database lookup and can be expensive for large recipient sets.

ParameterDescription
jobthe group or scheduled email job to find recipients for

findRecipients(BaseEmailJob job, JobStatus jobStatus)

Returns: List<ExtProfileBean>

Finds the profiles who will receive the given email job, after applying group or scheduled recipient rules and filtering out any without an email address, reporting progress through the given job status. This is a database lookup and can be expensive for large recipient sets.

ParameterDescription
jobthe group or scheduled email job to find recipients for
jobStatusreceives progress updates while recipients are being resolved

findByDate(Date start, Date finish)

Returns: List<GroupEmailJob>

Finds group email jobs for the current tenant organisation with a status date within the given range, excluding templates. This is a database lookup over all of the organisation's group email jobs.

ParameterDescription
startthe earliest status date to include, exclusive
finishthe latest status date to include, exclusive

findGroupEmailsByOrg()

Returns: List<GroupEmailJob>

Finds the non-template group email jobs for the current tenant organisation. This is a database lookup.

getGroupEmailLimit()

Returns: Integer

The maximum number of recipients allowed for a single group email, as configured for the email app on the current tenant.

emailBuilder()

Returns: EmailItemBuilder

Creates a new EmailItemBuilder for the current tenant organisation, used to set the recipient, sender, subject and body of an email before building and sending it.

getEmailTemplates()

Returns: List

Finds the group email jobs stored as templates for the current tenant organisation. This is a database lookup.

emailSearch(String q, Long funnelId, BaseEmailJob job, Date startDate, Date endDate, Integer startRow, Integer maxSize)

Returns: KSearchResponse

Searches indexed email items in elasticsearch, optionally filtered by free text over the from address, recipient address and subject, by funnel, by job and by a created date range. Results are sorted by created date, descending. This is a search index query, not a direct database read.

ParameterDescription
qfree text to search for across the from address, recipient address and subject, or null or blank to skip text filtering
funnelIdrestricts results to email items linked to this funnel, or null to skip this filter
jobrestricts results to email items belonging to this email job, or null to skip this filter
startDaterestricts results to items created on or after this date, or null to skip this bound
endDaterestricts results to items created on or before this date, or null to skip this bound
startRowunused by the current implementation, present for future paging support
maxSizeunused by the current implementation, present for future paging support

findJobsByDate(Date startDate, Date finish)

Returns: List<BaseEmailJob>

Finds email jobs for the current tenant organisation with a status date within the given range. This is a database lookup.

ParameterDescription
startDatethe earliest status date to include
finishthe latest status date to include

emailStatsDb(BaseEmailJob j, Date startDate, Date finish)

Returns: EmailStatusCounts

Counts email items for a job within a date range, split by send status, read status and conversion status. This is a query on the primary database rather than the search index, so it does not apply an organisation hierarchy filter, but it is the most authoritative source of counts.

ParameterDescription
jrestricts the count to email items belonging to this job, or null to count across all jobs
startDaterestricts the count to items created on or after this date, or null to skip this bound
finishrestricts the count to items created on or before this date, or null to skip this bound

emailStats(BaseEmailJob j, Date startDate, Date endDate)

Returns: EmailStatusCounts

Counts email items for a job within a date range, split by send status, read status and conversion status. This is a search index query restricted to organisations within the current selected organisation hierarchy, unlike emailStatsDb which queries the primary database without that filter.

ParameterDescription
jrestricts the count to email items belonging to this job, or null to count across all jobs
startDaterestricts the count to items created on or after this date, or null to skip this bound
endDaterestricts the count to items created on or before this date, or null to skip this bound

getEmailContent(EmailItem emailItem)

Returns: EmailContent

Retrieves the stored HTML and text content for an email item, using the currently registered content service.

ParameterDescription
emailItemthe email item to read content for

parseEmailAddress(String emailAddress)

Returns: MailboxAddress

Parses an email address string, which may carry a display name, into a MailboxAddress.

ParameterDescription
emailAddressthe address to parse, such as "Joe Bloggs less-than joe at bloggs.com greater-than" or a bare address

emailItemUpdated(EmailItem emailItem)

Returns: void

Saves an email item and fires an indexed-item-updated event so the search index picks up its new state.

ParameterDescription
emailItemthe email item that was changed

updateEmailComplete(EmailItem emailItem, boolean fireEvent)

Returns: void

Marks an email item as sent, recording the send status and its date, and saves it. Optionally fires an EmailDeliveryEvent so listeners can react to the delivery.

ParameterDescription
emailItemthe email item that was delivered
fireEventtrue to fire an EmailDeliveryEvent for the delivery

updateEmailFailed(EmailItem emailItem, boolean fireEvent)

Returns: void

Marks an email item as failed to send, recording the send status and its date, and saves it. Optionally fires an EmailDeliveryEvent so listeners can react to the failure.

ParameterDescription
emailItemthe email item that failed to send
fireEventtrue to fire an EmailDeliveryEvent for the failure

updateEmailOpened(EmailItem emailItem, boolean fireEvent)

Returns: void

Marks an email item as read and saves it. Optionally fires an EmailDeliveryEvent so listeners can react to the open.

ParameterDescription
emailItemthe email item that was opened
fireEventtrue to fire an EmailDeliveryEvent for the open

updateEmailConverted(EmailItem emailItem, boolean fireEvent)

Returns: void

Marks an email item as read and converted, and saves it. Optionally fires an EmailDeliveryEvent for the open and, if the item is linked to a funnel lead, updates that lead so its engagement score reflects the conversion.

ParameterDescription
emailItemthe email item that was converted
fireEventtrue to fire an EmailDeliveryEvent and update any linked lead

createSendAttempt(EmailItem emailItem)

Returns: EmailSendAttempt

Creates and saves a new EmailSendAttempt for an email item, recording it against the item's list of send attempts.

ParameterDescription
emailItemthe email item a send is being attempted for

sendAttemptUpdated(EmailSendAttempt esa)

Returns: void

Saves changes to an existing send attempt.

ParameterDescription
esathe send attempt that was changed

getAutomationEmailLimit()

Returns: Integer

The maximum number of recipients allowed for a single automated email, for the current tenant organisation.

getAutomationEmailLimit(Organisation adminOrg)

Returns: Integer

The maximum number of recipients allowed for a single automated email, for the given organisation.

ParameterDescription
adminOrgthe organisation to look up the limit for

createEmailTemplate(String templateName, String title, String subject, String emailBody, Website website)

Returns: GroupEmailJob

Creates and saves a new group email job of type TEMPLATE for the current tenant organisation, and reports the creation to account telemetry.

ParameterDescription
templateNamethe internal name of the template, used to identify it
titlethe display title of the template
subjectthe email subject line for messages built from this template
emailBodythe HTML body of the template
websitethe website the template is themed against

findGroupEmailType(String type)

Returns: GroupEmailType

Parses a group email type from its name.

ParameterDescription
typethe name of the group email type, such as "TEMPLATE" or "EMAIL"

addGroupRecipient(BaseEmailJob emailJob, Group group, boolean exclusion)

Returns: GroupRecipient

Adds a group to an email job's recipient list and saves the new recipient link.

ParameterDescription
emailJobthe email job to add the group recipient to
groupthe group to add
exclusiontrue means the group is excluded, so its members must not receive the email

removeGroupRecipient(BaseEmailJob emailJob, Group group, boolean exclusion)

Returns: void

Removes a group from an email job's recipient list.

ParameterDescription
emailJobthe email job to remove the group recipient from
groupthe group to remove
exclusiontrue means the group was excluded, so its members were not receiving the email

addOrganisationRecipient(BaseEmailJob emailJob, Organisation organisation, boolean exclusion)

Returns: OrganisationRecipient

Adds an organisation to an email job's recipient list and saves the new recipient link.

ParameterDescription
emailJobthe email job to add the organisation recipient to
organisationthe organisation to add
exclusiontrue means the organisation is excluded, so its members must not receive the email

removeOrganisationRecipient(BaseEmailJob emailJob, Organisation organisation, boolean exclusion)

Returns: void

Removes an organisation from an email job's recipient list.

ParameterDescription
emailJobthe email job to remove the organisation recipient from
organisationthe organisation to remove
exclusiontrue means the organisation was excluded, so its members were not receiving the email

findBaseEmailJobById(Long id)

Returns: BaseEmailJob

Finds the email job with the given ID belonging to the current tenant organisation. This is a database lookup.

ParameterDescription
idthe ID of the email job to find

isEmailAdministrator(Profile profile)

Returns: boolean

Checks whether a profile holds the admin or email administrator role.

ParameterDescription
profilethe profile to check

isEmailEditor(Profile profile)

Returns: boolean

Checks whether a profile holds the admin, email administrator or email editor role.

ParameterDescription
profilethe profile to check

isEmailSender(Profile profile)

Returns: boolean

Checks whether a profile holds the admin, email administrator, email editor or email sender role.

ParameterDescription
profilethe profile to check

canViewRecipients(Profile profile)

Returns: boolean

Checks whether a profile holds the admin, user administrator or user viewer role.

ParameterDescription
profilethe profile to check
To get full access to the Kademi Hub existing customers can login here, or new customers can register here.