Class OutgoingEmail

java.lang.Object
com.google.gerrit.server.mail.send.OutgoingEmail

public final class OutgoingEmail extends Object
Represents an email notification for some event that can be sent to interested parties.
  • Constructor Details

  • Method Details

    • setFrom

      public void setFrom(Account.Id id)
      Specify the account that triggered the notification.
    • getFrom

      public Account.Id getFrom()
      Get the account that triggered the notification.
    • setNotify

      public void setNotify(NotifyResolver.Result notify)
      Set how widely the email notification is allowed to be sent.
    • getNotify

      public NotifyResolver.Result getNotify()
      Returns the setting that controls how widely the email notification is allowed to be sent.
    • setMessageId

      public void setMessageId(MessageIdGenerator.MessageId messageId)
      Set identifier for the email. Every email must have one.
    • send

      public void send() throws com.google.gerrit.exceptions.EmailException
      Format and enqueue the message for delivery.
      Throws:
      com.google.gerrit.exceptions.EmailException
    • init

      public void init() throws com.google.gerrit.exceptions.EmailException
      Setup the message headers and envelope (TO, CC, BCC).
      Throws:
      com.google.gerrit.exceptions.EmailException - if an error occurred.
    • getGerritHost

      public String getGerritHost()
    • getSettingsUrl

      public String getSettingsUrl()
    • getSettingsUrl

      public String getSettingsUrl(String section)
    • setHeader

      public void setHeader(String name, String value)
      Set a header in the outgoing message.
    • removeHeader

      public void removeHeader(String name)
      Remove a header from the outgoing message.
    • setHeader

      public void setHeader(String name, Instant date)
      Set a date header in the outgoing message.
    • appendText

      public void appendText(String text)
      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

      public String getNameFor(Account.Id accountId)
      Lookup a human readable name for an account, usually the "full name".
    • getNameEmailFor

      public String getNameEmailFor(Account.Id accountId)
      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

      public String getUserNameEmailFor(Account.Id accountId)
      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

      public final void addByEmail(RecipientType rt, Address addr)
      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

      public final void addByEmail(RecipientType rt, Address addr, boolean override)
      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 of rt.
    • isRecipientAllowed

      public boolean isRecipientAllowed(Address addr) throws PermissionBackendException
      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

      public void addByAccountId(RecipientType rt, Account.Id to)
      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

      public void addByAccountId(RecipientType rt, Account.Id to, boolean override)
      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 of rt.
    • isRecipientAllowed

      public boolean isRecipientAllowed(Account.Id to) throws PermissionBackendException
      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

      public Address toAddress(Account.Id id)
      Returns preferred email address for the account.
    • getMessageClass

      public String getMessageClass()
      Returns the type of notification being sent.
    • populateEmailContent

      public void populateEmailContent() throws com.google.gerrit.exceptions.EmailException
      Set recipients, headers, body of the email.
      Throws:
      com.google.gerrit.exceptions.EmailException
    • addSoyParam

      public void addSoyParam(String key, Object value)
      Adds param to the data map passed into soy when rendering templates.
    • addSoyEmailDataParam

      public void addSoyEmailDataParam(String key, Object value)
      Adds entry to the `email` param passed to the soy when rendering templates.
    • addFooter

      public void addFooter(String footer)
      Add a line to email footer with additional information. Typically, in the form of <key>: <value>.
    • addHtmlResource

      public void addHtmlResource(EmailResource resource)
      Add a resource that can be referenced in HTML code using their EmailResource.contentId().
    • textTemplate

      public String textTemplate(String name)
      Renders a soy template of kind="text".
    • soyHtmlTemplate

      public com.google.template.soy.data.SanitizedContent soyHtmlTemplate(String name)
      Renders a soy template of kind="html".
    • soyCssTemplate

      public com.google.template.soy.data.SanitizedContent soyCssTemplate(String name)
      Renders a soy template of kind="css".
    • useHtml

      public boolean useHtml()
      Return true, if the email should include html body.