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
Modifier and Type | Field and Description |
---|---|
static long |
testingEmailCount
keep count for testing
|
Constructor and Description |
---|
GrouperEmail() |
Modifier and Type | Method and Description |
---|---|
static boolean |
addAllowEmailToGroup(String address)
add an email allowed to the list of allowed emails in config
|
GrouperEmail |
addEmailAddressToBcc(String emailAddress)
add email address (if not blank) to bcc
|
GrouperEmail |
addEmailAddressToCc(String emailAddress)
add email address (if not blank) to cc
|
GrouperEmail |
addEmailAddressToSendTo(String emailAddress)
add email address (if not blank) to send to.
|
GrouperEmail |
addGroupNameToBcc(String groupName,
boolean exceptionIfNotFound)
add a group of people to bcc
|
GrouperEmail |
addGroupNameToCc(String groupName,
boolean exceptionIfNotFound)
add a group of people to cc
|
GrouperEmail |
addGroupNameToSendTo(String groupName,
boolean exceptionIfNotFound)
add a group of people to send to
|
GrouperEmail |
addGroupToBcc(Group group)
add a group of people to bcc
|
GrouperEmail |
addGroupToCc(Group group)
add a group of people to cc
|
GrouperEmail |
addGroupToSendTo(Group group)
add a group of people to send to.
|
GrouperEmail |
addGroupUuidToBcc(String groupUuid,
boolean exceptionIfNotFound)
add a group of people to bcc
|
GrouperEmail |
addGroupUuidToCc(String groupUuid,
boolean exceptionIfNotFound)
add a group of people to cc
|
GrouperEmail |
addGroupUuidToSendTo(String groupUuid,
boolean exceptionIfNotFound)
add a group of people to send to
|
GrouperEmail |
addSubjectIdentifierToBcc(String sourceId,
String subjectIdentifier)
find a subject by sourceId and subjectId, if not found, do nothing.
|
GrouperEmail |
addSubjectIdentifierToCc(String sourceId,
String subjectIdentifier)
find a subject by sourceId and subjectId, if not found, do nothing.
|
GrouperEmail |
addSubjectIdentifierToSendTo(String sourceId,
String subjectIdentifier)
find a subject by sourceId and subjectId, if not found, do nothing.
|
GrouperEmail |
addSubjectIdToBcc(String sourceId,
String subjectId)
find a subject by sourceId and subjectId, if not found, do nothing.
|
GrouperEmail |
addSubjectIdToCc(String sourceId,
String subjectId)
find a subject by sourceId and subjectId, if not found, do nothing.
|
GrouperEmail |
addSubjectIdToSendTo(String sourceId,
String subjectId)
find a subject by sourceId and subjectId, if not found, do nothing.
|
GrouperEmail |
addSubjectToBcc(Subject subject)
add a subject (e.g.
|
GrouperEmail |
addSubjectToCc(Subject subject)
add subject (e.g.
|
GrouperEmail |
addSubjectToSendTo(Subject subject)
add a subject (person) to send email to.
|
GrouperEmail |
assignRunAsRoot(boolean runAsRoot)
set this to true to run as a root session.
|
static List<String> |
externalSystemTest() |
String |
getBcc()
optional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emails
|
String |
getBody()
body of email (HTML if the email starts with open HTML bracket <)
|
String |
getCc()
optional comma-separated or semicolon separated list of Cc addresses to send to
|
String |
getFrom()
set the from address.
|
String |
getReplyTo()
optional comma-separated list of addresses for Reply-To header
|
String |
getSubject()
subject of email
|
String |
getTo()
set the to addresses (comma separated or semicolon separated)
|
boolean |
isMailSent()
if mail was sent
|
static void |
main(String[] args)
try an email
|
static boolean |
removeAllowEmailToGroup(String address)
remove an allowed email address from the list of allwoed emails in config
|
static String |
retrieveEmailAddress(Subject subject)
get an email address for a subject or null if email not found
|
static Set<String> |
retrieveEmailAddresses(Group group,
boolean secure)
secure? method that retrieves email addresses from a group
|
static Set<String> |
retrieveEmailAddresses(String groupName,
boolean secure,
boolean exceptionIfNotFound)
secure? method that retrieves email addresses from a group
|
static Set<String> |
retrieveEmailAddressesByGroupUuid(String groupUuid,
boolean secure,
boolean exceptionIfNotFound)
secure? method that retrieves email addresses from a group
|
void |
send()
send the email
|
GrouperEmail |
setBcc(String theBcc)
optional comma-separated or semicolon separated list of Bcc (blind carbon copy) addresses to send to for all emails
|
GrouperEmail |
setBody(String theBody)
body of email (HTML if the email starts with open HTML bracket <)
|
GrouperEmail |
setCc(String theCc)
optional comma-separated or semicolon separated list of Cc addresses to send to
|
GrouperEmail |
setFrom(String theFrom)
set the from address.
|
GrouperEmail |
setReplyTo(String theReplyTo)
optional comma-separated list of addresses for Reply-To header
|
GrouperEmail |
setSubject(String theSubject)
set email subject
|
GrouperEmail |
setTo(String theToAddress)
set the to addresses (comma separated or semicolon separated).
|
static List<GrouperEmail> |
testingEmails() |
public static boolean addAllowEmailToGroup(String address)
address
- public static boolean removeAllowEmailToGroup(String address)
address
- public GrouperEmail addSubjectToSendTo(Subject subject)
subject
- public GrouperEmail addSubjectIdentifierToSendTo(String sourceId, String subjectIdentifier)
sourceId
- subjectId
- public GrouperEmail addSubjectIdToSendTo(String sourceId, String subjectId)
sourceId
- subjectId
- public static String retrieveEmailAddress(Subject subject)
subject
- to send email topublic static Set<String> retrieveEmailAddresses(String groupName, boolean secure, boolean exceptionIfNotFound)
group
- namesecure
- false to run as rootexceptionIfNotFound
- exception if group not foundpublic static Set<String> retrieveEmailAddresses(Group group, boolean secure)
group
- public static List<GrouperEmail> testingEmails()
public String getTo()
public String getCc()
public String getBcc()
public String getReplyTo()
public String getSubject()
public String getFrom()
public String getBody()
public GrouperEmail setTo(String theToAddress)
theToAddress
- public GrouperEmail setCc(String theCc)
theCc
- public GrouperEmail setBcc(String theBcc)
theBcc
- public GrouperEmail setReplyTo(String theReplyTo)
theReplyTo
- public GrouperEmail setSubject(String theSubject)
theSubject
- public GrouperEmail setBody(String theBody)
theBody
- public GrouperEmail setFrom(String theFrom)
theFrom
- public static void main(String[] args)
args
- public boolean isMailSent()
public void send()
public GrouperEmail addSubjectIdentifierToCc(String sourceId, String subjectIdentifier)
sourceId
- subjectId
- public GrouperEmail addSubjectIdToCc(String sourceId, String subjectId)
sourceId
- subjectId
- public GrouperEmail addSubjectToCc(Subject subject)
subject
- public GrouperEmail addSubjectIdentifierToBcc(String sourceId, String subjectIdentifier)
sourceId
- subjectId
- public GrouperEmail addSubjectIdToBcc(String sourceId, String subjectId)
sourceId
- subjectId
- public GrouperEmail addGroupToSendTo(Group group)
subject
- public GrouperEmail addGroupToCc(Group group)
subject
- public GrouperEmail assignRunAsRoot(boolean runAsRoot)
runAsRoot
- public GrouperEmail addGroupToBcc(Group group)
subject
- public GrouperEmail addEmailAddressToSendTo(String emailAddress)
emailAddress
- public GrouperEmail addEmailAddressToCc(String emailAddress)
emailAddress
- public GrouperEmail addEmailAddressToBcc(String emailAddress)
emailAddress
- public GrouperEmail addSubjectToBcc(Subject subject)
subject
- public GrouperEmail addGroupNameToBcc(String groupName, boolean exceptionIfNotFound)
groupName
- full system name of groupexceptionIfNotFound
- true if exception if group not foundpublic GrouperEmail addGroupNameToCc(String groupName, boolean exceptionIfNotFound)
groupName
- full system name of groupexceptionIfNotFound
- true if exception if group not foundpublic GrouperEmail addGroupNameToSendTo(String groupName, boolean exceptionIfNotFound)
groupName
- full system name of groupexceptionIfNotFound
- true if exception if group not foundpublic GrouperEmail addGroupUuidToBcc(String groupUuid, boolean exceptionIfNotFound)
groupUuid
- group uuid of groupexceptionIfNotFound
- true if exception if group not foundpublic GrouperEmail addGroupUuidToCc(String groupUuid, boolean exceptionIfNotFound)
groupUuid
- group uuid of groupexceptionIfNotFound
- true if exception if group not foundpublic GrouperEmail addGroupUuidToSendTo(String groupUuid, boolean exceptionIfNotFound)
groupUuid
- group uuid of groupexceptionIfNotFound
- true if exception if group not foundpublic static Set<String> retrieveEmailAddressesByGroupUuid(String groupUuid, boolean secure, boolean exceptionIfNotFound)
group
- secure
- is false if run as rootexceptionIfNotFound
- true if exception if not foundCopyright © 2016 Internet2. All rights reserved.