Class OutgoingEmail
java.lang.Object
com.google.gerrit.server.mail.send.OutgoingEmail
Represents an email notification for some event that can be sent to interested parties.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Provides content, recipients and any customizations of the email. -
Constructor Summary
ConstructorsConstructorDescriptionOutgoingEmail
(EmailArguments args, String messageClass, OutgoingEmail.EmailDecorator templateProvider) -
Method Summary
Modifier and TypeMethodDescriptionvoid
addByAccountId
(RecipientType rt, Account.Id to) Adds a recipient that the email will be sent to.void
addByAccountId
(RecipientType rt, Account.Id to, boolean override) Adds a recipient that the email will be sent to.final void
addByEmail
(RecipientType rt, Address addr) Adds a recipient that the email will be sent to.final void
addByEmail
(RecipientType rt, Address addr, boolean override) Adds a recipient that the email will be sent to.void
Add a line to email footer with additional information.void
addHtmlResource
(EmailResource resource) Add a resource that can be referenced in HTML code using theirEmailResource.contentId()
.void
addSoyEmailDataParam
(String key, Object value) Adds entry to the `email` param passed to the soy when rendering templates.void
addSoyParam
(String key, Object value) Adds param to the data map passed into soy when rendering templates.void
appendHtml
(com.google.template.soy.data.SanitizedContent html) Append html to the outgoing email body.void
appendText
(String text) Append text to the outgoing email body.getFrom()
Get the account that triggered the notification.Returns the type of notification being sent.getNameEmailFor
(Account.Id accountId) Gets the human readable name and email for an account; if neither are available, returns the Anonymous Coward name.getNameFor
(Account.Id accountId) Lookup a human readable name for an account, usually the "full name".Returns the setting that controls how widely the email notification is allowed to be sent.getSettingsUrl
(String section) getUserNameEmailFor
(Account.Id accountId) Gets the human readable name and email for an account; if both are unavailable, returns the username.void
init()
Setup the message headers and envelope (TO, CC, BCC).boolean
Returns whether this email is allowed to be sent to the given accountboolean
isRecipientAllowed
(Address addr) Returns whether this email is allowed to be sent to the given addressvoid
Set recipients, headers, body of the email.void
removeHeader
(String name) Remove a header from the outgoing message.void
send()
Format and enqueue the message for delivery.void
setFrom
(Account.Id id) Specify the account that triggered the notification.void
Set a header in the outgoing message.void
Set a date header in the outgoing message.void
setMessageId
(MessageIdGenerator.MessageId messageId) Set identifier for the email.void
setNotify
(NotifyResolver.Result notify) Set how widely the email notification is allowed to be sent.com.google.template.soy.data.SanitizedContent
soyCssTemplate
(String name) Renders a soy template of kind="css".com.google.template.soy.data.SanitizedContent
soyHtmlTemplate
(String name) Renders a soy template of kind="html".textTemplate
(String name) Renders a soy template of kind="text".toAddress
(Account.Id id) Returns preferred email address for the account.boolean
useHtml()
Return true, if the email should include html body.
-
Constructor Details
-
OutgoingEmail
public OutgoingEmail(EmailArguments args, String messageClass, OutgoingEmail.EmailDecorator templateProvider)
-
-
Method Details
-
setFrom
Specify the account that triggered the notification. -
getFrom
Get the account that triggered the notification. -
setNotify
Set how widely the email notification is allowed to be sent. -
getNotify
Returns the setting that controls how widely the email notification is allowed to be sent. -
setMessageId
Set identifier for the email. Every email must have one. -
send
public void send() throws com.google.gerrit.exceptions.EmailExceptionFormat and enqueue the message for delivery.- Throws:
com.google.gerrit.exceptions.EmailException
-
init
public void init() throws com.google.gerrit.exceptions.EmailExceptionSetup the message headers and envelope (TO, CC, BCC).- Throws:
com.google.gerrit.exceptions.EmailException
- if an error occurred.
-
getGerritHost
-
getSettingsUrl
-
getSettingsUrl
-
setHeader
Set a header in the outgoing message. -
removeHeader
Remove a header from the outgoing message. -
setHeader
Set a date header in the outgoing message. -
appendText
Append text to the outgoing email body. -
appendHtml
public void appendHtml(com.google.template.soy.data.SanitizedContent html) Append html to the outgoing email body. -
getNameFor
Lookup a human readable name for an account, usually the "full name". -
getNameEmailFor
Gets the human readable name and email for an account; if neither are available, returns the Anonymous Coward name.- Parameters:
accountId
- user to fetch.- Returns:
- name/email of account, or Anonymous Coward if unset.
-
getUserNameEmailFor
Gets the human readable name and email for an account; if both are unavailable, returns the username. If no username is set, this function returns null.- Parameters:
accountId
- user to fetch.- Returns:
- name/email of account, username, or null if unset or the accountId is null.
-
addByEmail
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC)addr
- Name and email of the recipient.
-
addByEmail
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC).addr
- Name and email of the recipient.override
- if the recipient was added previously and override is false no change is made regardless ofrt
.
-
isRecipientAllowed
Returns whether this email is allowed to be sent to the given address- Parameters:
addr
- email address of recipient.- Throws:
PermissionBackendException
- thrown if checking a permission fails due to an error in the permission backend
-
addByAccountId
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC)to
- Gerrit Account of the recipient.
-
addByAccountId
Adds a recipient that the email will be sent to.- Parameters:
rt
- category of recipient (TO, CC, BCC)to
- Gerrit Account of the recipient.override
- if the recipient was added previously and override is false no change is made regardless ofrt
.
-
isRecipientAllowed
Returns whether this email is allowed to be sent to the given account- Parameters:
to
- account.- Throws:
PermissionBackendException
- thrown if checking a permission fails due to an error in the permission backend
-
toAddress
Returns preferred email address for the account. -
getMessageClass
Returns the type of notification being sent. -
populateEmailContent
public void populateEmailContent() throws com.google.gerrit.exceptions.EmailExceptionSet recipients, headers, body of the email.- Throws:
com.google.gerrit.exceptions.EmailException
-
addSoyParam
Adds param to the data map passed into soy when rendering templates. -
addSoyEmailDataParam
Adds entry to the `email` param passed to the soy when rendering templates. -
addHtmlResource
Add a resource that can be referenced in HTML code using theirEmailResource.contentId()
. -
textTemplate
Renders a soy template of kind="text". -
soyHtmlTemplate
Renders a soy template of kind="html". -
soyCssTemplate
Renders a soy template of kind="css". -
useHtml
public boolean useHtml()Return true, if the email should include html body.
-