Class GrouperEmail
java.lang.Object
edu.internet2.middleware.grouper.util.GrouperEmail
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 Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
addAllowEmailToGroup
(String address) add an email allowed to the list of allowed emails in configaddAttachment
(File attachment) Add a file attachment to the email.addEmailAddressToBcc
(String emailAddress) add email address (if not blank) to bccaddEmailAddressToCc
(String emailAddress) add email address (if not blank) to ccaddEmailAddressToSendTo
(String emailAddress) add email address (if not blank) to send to.addGroupNameToBcc
(String groupName, boolean exceptionIfNotFound) add a group of people to bccaddGroupNameToCc
(String groupName, boolean exceptionIfNotFound) add a group of people to ccaddGroupNameToSendTo
(String groupName, boolean exceptionIfNotFound) add a group of people to send toaddGroupToBcc
(Group group) add a group of people to bccaddGroupToCc
(Group group) add a group of people to ccaddGroupToSendTo
(Group group) add a group of people to send to.addGroupUuidToBcc
(String groupUuid, boolean exceptionIfNotFound) add a group of people to bccaddGroupUuidToCc
(String groupUuid, boolean exceptionIfNotFound) add a group of people to ccaddGroupUuidToSendTo
(String groupUuid, boolean exceptionIfNotFound) add a group of people to send toaddSubjectIdentifierToBcc
(String sourceId, String subjectIdentifier) find a subject by sourceId and subjectId, if not found, do nothing.addSubjectIdentifierToCc
(String sourceId, String subjectIdentifier) find a subject by sourceId and subjectId, if not found, do nothing.addSubjectIdentifierToSendTo
(String sourceId, String subjectIdentifier) find a subject by sourceId and subjectId, if not found, do nothing.addSubjectIdToBcc
(String sourceId, String subjectId) find a subject by sourceId and subjectId, if not found, do nothing.addSubjectIdToCc
(String sourceId, String subjectId) find a subject by sourceId and subjectId, if not found, do nothing.addSubjectIdToSendTo
(String sourceId, String subjectId) find a subject by sourceId and subjectId, if not found, do nothing.addSubjectToBcc
(Subject subject) add a subject (e.g.addSubjectToCc
(Subject subject) add subject (e.g.addSubjectToSendTo
(Subject subject) add a subject (person) to send email to.assignRunAsRoot
(boolean runAsRoot) set this to true to run as a root session.get the attachmentsgetBcc()
optional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emailsgetBody()
body of email (HTML if the email starts with open HTML bracket <)getCc()
optional comma-separated or semicolon separated list of Cc addresses to send togetFrom()
set the from address.optional comma-separated list of addresses for Reply-To headersubject of emailgetTo()
set the to addresses (comma separated or semicolon separated)boolean
if mail was sentstatic void
try an emailstatic boolean
removeAllowEmailToGroup
(String address) remove an allowed email address from the list of allwoed emails in configstatic String
retrieveEmailAddress
(Subject subject) get an email address for a subject or null if email not foundretrieveEmailAddresses
(Group group, boolean secure) secure? method that retrieves email addresses from a groupretrieveEmailAddresses
(String groupName, boolean secure, boolean exceptionIfNotFound) secure? method that retrieves email addresses from a groupretrieveEmailAddressesByGroupUuid
(String groupUuid, boolean secure, boolean exceptionIfNotFound) secure? method that retrieves email addresses from a groupvoid
send()
send the emailoptional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emailsbody of email (HTML if the email starts with open HTML bracket <)optional comma-separated or semicolon separated list of Cc addresses to send toset the from address.setReplyTo
(String theReplyTo) optional comma-separated list of addresses for Reply-To headersetSubject
(String theSubject) set email subjectset the to addresses (comma separated or semicolon separated).static List<GrouperEmail>
-
Field Details
-
testingEmailCount
public static long testingEmailCountkeep count for testing
-
-
Constructor Details
-
GrouperEmail
public GrouperEmail()
-
-
Method Details
-
addAttachment
Add a file attachment to the email.- Parameters:
attachment
-- Returns:
- the email.
-
getAttachments
get the attachments- Returns:
- attachemnts
-
addAllowEmailToGroup
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
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
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
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
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
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
- namesecure
- false to run as rootexceptionIfNotFound
- exception if group not found- Returns:
- the email addresses found for users in the group
-
retrieveEmailAddresses
secure? method that retrieves email addresses from a group- Parameters:
group
-- Returns:
- the email addresses found for users in the group
-
testingEmails
- Returns:
- the list of emails
-
getTo
set the to addresses (comma separated or semicolon separated)- Returns:
- to
-
getCc
optional comma-separated or semicolon separated list of Cc addresses to send to- Returns:
-
getBcc
optional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emails- Returns:
-
getReplyTo
optional comma-separated list of addresses for Reply-To header- Returns:
-
getSubject
subject of email- Returns:
- subject
-
getFrom
set the from address. generally this will not be set and will come from the config default- Returns:
- from
-
getBody
body of email (HTML if the email starts with open HTML bracket <)- Returns:
- body
-
setTo
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
optional comma-separated or semicolon separated list of Cc addresses to send to- Parameters:
theCc
-
-
setBcc
optional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emails- Parameters:
theBcc
-
-
setReplyTo
optional comma-separated list of addresses for Reply-To header- Parameters:
theReplyTo
-
-
setSubject
set email subject- Parameters:
theSubject
-- Returns:
- this for chaining
-
setBody
body of email (HTML if the email starts with open HTML bracket <)- Parameters:
theBody
-- Returns:
- this for chaining
-
setFrom
set the from address. generally this will not be set and will come from the config default- Parameters:
theFrom
-- Returns:
- the from address
-
main
try an email- Parameters:
args
-
-
isMailSent
public boolean isMailSent()if mail was sent- Returns:
- true
-
send
public void send()send the email -
addSubjectIdentifierToCc
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
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
add subject (e.g. person) to cc- Parameters:
subject
-- Returns:
- this for chaining
- Since:
- 2.5.47
-
addSubjectIdentifierToBcc
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
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
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
add a group of people to cc- Parameters:
subject
-- Returns:
- this for chaining
- Since:
- 2.5.47
-
assignRunAsRoot
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
add a group of people to bcc- Parameters:
subject
-- Returns:
- this for chaining
- Since:
- 2.5.47
-
addEmailAddressToSendTo
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
add email address (if not blank) to cc- Parameters:
emailAddress
-- Returns:
- this for chaining
- Since:
- 2.5.47
-
addEmailAddressToBcc
add email address (if not blank) to bcc- Parameters:
emailAddress
-- Returns:
- this for chaining
- Since:
- 2.5.47
-
addSubjectToBcc
add a subject (e.g. person) to bcc- Parameters:
subject
-- Returns:
- this for chaining
- Since:
- 2.5.47
-
addGroupNameToBcc
add a group of people to bcc- Parameters:
groupName
- full system name of groupexceptionIfNotFound
- true if exception if group not found- Returns:
- this for chaining
- Since:
- 2.5.47
-
addGroupNameToCc
add a group of people to cc- Parameters:
groupName
- full system name of groupexceptionIfNotFound
- true if exception if group not found- Returns:
- this for chaining
- Since:
- 2.5.47
-
addGroupNameToSendTo
add a group of people to send to- Parameters:
groupName
- full system name of groupexceptionIfNotFound
- true if exception if group not found- Returns:
- this for chaining
- Since:
- 2.5.47
-
addGroupUuidToBcc
add a group of people to bcc- Parameters:
groupUuid
- group uuid of groupexceptionIfNotFound
- true if exception if group not found- Returns:
- this for chaining
- Since:
- 2.5.47
-
addGroupUuidToCc
add a group of people to cc- Parameters:
groupUuid
- group uuid of groupexceptionIfNotFound
- true if exception if group not found- Returns:
- this for chaining
- Since:
- 2.5.47
-
addGroupUuidToSendTo
add a group of people to send to- Parameters:
groupUuid
- group uuid of groupexceptionIfNotFound
- 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 rootexceptionIfNotFound
- true if exception if not found- Returns:
- the email addresses found for users in the group
- Since:
- 2.5.47
-
externalSystemTest
-