Class GrouperEmail

java.lang.Object
edu.internet2.middleware.grouper.util.GrouperEmail

public class GrouperEmail extends Object

Use this utility to send email from Grouper. Many of these methods are new as of v2.5.47+. The original "set" methods have been there since v1.4+

Configured from the smtp external system: https://spaces.at.internet2.edu/display/Grouper/Grouper+smtp+external+system

Unlike most other method chaining classes, you need to call assignRunAsRoot(true) before adding subject and group lookups if you dont want to check security

Sample call to send an email:

new GrouperEmail().setTo("email@domain.com").setBody("email body").setSubject("email subject").send();

Send an email to a subject:

new GrouperEmail().assignRunAsRoot(true).addSubjectIdentifierToSendTo("mySourceId", "someNetId").setBody("email body").setSubject("email subject").send();

Sample call to send an email:

new GrouperEmail().assignRunAsRoot(true).addGroupToSendTo("a:b:c").setBody("email body").setSubject("email subject").send();

You need to configure email address in your person subject source to send to subjects

At least one "to" address is required.

To debug emails, set debug to true in the smtp external system, and set the log4j.properties entry:

log4j.logger.edu.internet2.middleware.grouper.util.GrouperEmail = DEBUG

  • Field Details

    • testingEmailCount

      public static long testingEmailCount
      keep count for testing
  • Constructor Details

    • GrouperEmail

      public GrouperEmail()
  • Method Details

    • addAttachment

      public GrouperEmail addAttachment(File attachment)
      Add a file attachment to the email.
      Parameters:
      attachment -
      Returns:
      the email.
    • getAttachments

      public List<File> getAttachments()
      get the attachments
      Returns:
      attachemnts
    • addAllowEmailToGroup

      public static boolean addAllowEmailToGroup(String address)
      add an email allowed to the list of allowed emails in config
      Parameters:
      address -
      Returns:
      true if added, false if already there
      Since:
      v2.5.48
    • removeAllowEmailToGroup

      public static boolean removeAllowEmailToGroup(String address)
      remove an allowed email address from the list of allwoed emails in config
      Parameters:
      address -
      Returns:
      true if removed, false if not there
      Since:
      v2.5.48
    • addSubjectToSendTo

      public GrouperEmail addSubjectToSendTo(Subject subject)
      add a subject (person) to send email to. The email will not send without "to" address(es)
      Parameters:
      subject -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addSubjectIdentifierToSendTo

      public GrouperEmail addSubjectIdentifierToSendTo(String sourceId, String subjectIdentifier)
      find a subject by sourceId and subjectId, if not found, do nothing. If found, find email address. If not found, do nothing. If found, add to the "to" address list. The email will not send without "to" address(es)
      Parameters:
      sourceId -
      subjectId -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addSubjectIdToSendTo

      public GrouperEmail addSubjectIdToSendTo(String sourceId, String subjectId)
      find a subject by sourceId and subjectId, if not found, do nothing. If found, find email address. If not found, do nothing. If found, add to the "to" address list. The email will not send without "to" address(es)
      Parameters:
      sourceId -
      subjectId -
      Returns:
      this for chaining
      Since:
      2.5.47
    • retrieveEmailAddress

      public static String retrieveEmailAddress(Subject subject)
      get an email address for a subject or null if email not found
      Parameters:
      subject - to send email to
      Returns:
      email address
    • retrieveEmailAddresses

      public static Set<String> retrieveEmailAddresses(String groupName, boolean secure, boolean exceptionIfNotFound)
      secure? method that retrieves email addresses from a group
      Parameters:
      group - name
      secure - false to run as root
      exceptionIfNotFound - exception if group not found
      Returns:
      the email addresses found for users in the group
    • retrieveEmailAddresses

      public static Set<String> retrieveEmailAddresses(Group group, boolean secure)
      secure? method that retrieves email addresses from a group
      Parameters:
      group -
      Returns:
      the email addresses found for users in the group
    • testingEmails

      public static List<GrouperEmail> testingEmails()
      Returns:
      the list of emails
    • getTo

      public String getTo()
      set the to addresses (comma separated or semicolon separated)
      Returns:
      to
    • getCc

      public String getCc()
      optional comma-separated or semicolon separated list of Cc addresses to send to
      Returns:
    • getBcc

      public String getBcc()
      optional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emails
      Returns:
    • getReplyTo

      public String getReplyTo()
      optional comma-separated list of addresses for Reply-To header
      Returns:
    • getSubject

      public String getSubject()
      subject of email
      Returns:
      subject
    • getFrom

      public String getFrom()
      set the from address. generally this will not be set and will come from the config default
      Returns:
      from
    • getBody

      public String getBody()
      body of email (HTML if the email starts with open HTML bracket <)
      Returns:
      body
    • setTo

      public GrouperEmail setTo(String theToAddress)
      set the to addresses (comma separated or semicolon separated). The email will not send without "to" address(es)
      Parameters:
      theToAddress -
      Returns:
      this for chaining
    • setCc

      public GrouperEmail setCc(String theCc)
      optional comma-separated or semicolon separated list of Cc addresses to send to
      Parameters:
      theCc -
    • setBcc

      public GrouperEmail setBcc(String theBcc)
      optional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emails
      Parameters:
      theBcc -
    • setReplyTo

      public GrouperEmail setReplyTo(String theReplyTo)
      optional comma-separated list of addresses for Reply-To header
      Parameters:
      theReplyTo -
    • setSubject

      public GrouperEmail setSubject(String theSubject)
      set email subject
      Parameters:
      theSubject -
      Returns:
      this for chaining
    • setBody

      public GrouperEmail setBody(String theBody)
      body of email (HTML if the email starts with open HTML bracket <)
      Parameters:
      theBody -
      Returns:
      this for chaining
    • setFrom

      public GrouperEmail setFrom(String theFrom)
      set the from address. generally this will not be set and will come from the config default
      Parameters:
      theFrom -
      Returns:
      the from address
    • main

      public static void main(String[] args)
      try an email
      Parameters:
      args -
    • isMailSent

      public boolean isMailSent()
      if mail was sent
      Returns:
      true
    • send

      public void send()
      send the email
    • addSubjectIdentifierToCc

      public GrouperEmail addSubjectIdentifierToCc(String sourceId, String subjectIdentifier)
      find a subject by sourceId and subjectId, if not found, do nothing. If found, find email address. If not found, do nothing. If found, add to the "cc" address list
      Parameters:
      sourceId -
      subjectId -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addSubjectIdToCc

      public GrouperEmail addSubjectIdToCc(String sourceId, String subjectId)
      find a subject by sourceId and subjectId, if not found, do nothing. If found, find email address. If not found, do nothing. If found, add to the "cc" address list
      Parameters:
      sourceId -
      subjectId -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addSubjectToCc

      public GrouperEmail addSubjectToCc(Subject subject)
      add subject (e.g. person) to cc
      Parameters:
      subject -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addSubjectIdentifierToBcc

      public GrouperEmail addSubjectIdentifierToBcc(String sourceId, String subjectIdentifier)
      find a subject by sourceId and subjectId, if not found, do nothing. If found, find email address. If not found, do nothing. If found, add to the "bcc" address list
      Parameters:
      sourceId -
      subjectId -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addSubjectIdToBcc

      public GrouperEmail addSubjectIdToBcc(String sourceId, String subjectId)
      find a subject by sourceId and subjectId, if not found, do nothing. If found, find email address. If not found, do nothing. If found, add to the "bcc" address list
      Parameters:
      sourceId -
      subjectId -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupToSendTo

      public GrouperEmail addGroupToSendTo(Group group)
      add a group of people to send to. The email will not send without "to" address(es)
      Parameters:
      subject -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupToCc

      public GrouperEmail addGroupToCc(Group group)
      add a group of people to cc
      Parameters:
      subject -
      Returns:
      this for chaining
      Since:
      2.5.47
    • assignRunAsRoot

      public GrouperEmail assignRunAsRoot(boolean runAsRoot)
      set this to true to run as a root session. Note you need to set this before adding subjects and groups to look up
      Parameters:
      runAsRoot -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupToBcc

      public GrouperEmail addGroupToBcc(Group group)
      add a group of people to bcc
      Parameters:
      subject -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addEmailAddressToSendTo

      public GrouperEmail addEmailAddressToSendTo(String emailAddress)
      add email address (if not blank) to send to. The email will not send without "to" address(es)
      Parameters:
      emailAddress -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addEmailAddressToCc

      public GrouperEmail addEmailAddressToCc(String emailAddress)
      add email address (if not blank) to cc
      Parameters:
      emailAddress -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addEmailAddressToBcc

      public GrouperEmail addEmailAddressToBcc(String emailAddress)
      add email address (if not blank) to bcc
      Parameters:
      emailAddress -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addSubjectToBcc

      public GrouperEmail addSubjectToBcc(Subject subject)
      add a subject (e.g. person) to bcc
      Parameters:
      subject -
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupNameToBcc

      public GrouperEmail addGroupNameToBcc(String groupName, boolean exceptionIfNotFound)
      add a group of people to bcc
      Parameters:
      groupName - full system name of group
      exceptionIfNotFound - true if exception if group not found
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupNameToCc

      public GrouperEmail addGroupNameToCc(String groupName, boolean exceptionIfNotFound)
      add a group of people to cc
      Parameters:
      groupName - full system name of group
      exceptionIfNotFound - true if exception if group not found
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupNameToSendTo

      public GrouperEmail addGroupNameToSendTo(String groupName, boolean exceptionIfNotFound)
      add a group of people to send to
      Parameters:
      groupName - full system name of group
      exceptionIfNotFound - true if exception if group not found
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupUuidToBcc

      public GrouperEmail addGroupUuidToBcc(String groupUuid, boolean exceptionIfNotFound)
      add a group of people to bcc
      Parameters:
      groupUuid - group uuid of group
      exceptionIfNotFound - true if exception if group not found
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupUuidToCc

      public GrouperEmail addGroupUuidToCc(String groupUuid, boolean exceptionIfNotFound)
      add a group of people to cc
      Parameters:
      groupUuid - group uuid of group
      exceptionIfNotFound - true if exception if group not found
      Returns:
      this for chaining
      Since:
      2.5.47
    • addGroupUuidToSendTo

      public GrouperEmail addGroupUuidToSendTo(String groupUuid, boolean exceptionIfNotFound)
      add a group of people to send to
      Parameters:
      groupUuid - group uuid of group
      exceptionIfNotFound - true if exception if group not found
      Returns:
      this for chaining
      Since:
      2.5.47
    • retrieveEmailAddressesByGroupUuid

      public static Set<String> retrieveEmailAddressesByGroupUuid(String groupUuid, boolean secure, boolean exceptionIfNotFound)
      secure? method that retrieves email addresses from a group
      Parameters:
      group -
      secure - is false if run as root
      exceptionIfNotFound - true if exception if not found
      Returns:
      the email addresses found for users in the group
      Since:
      2.5.47
    • externalSystemTest

      public static List<String> externalSystemTest()