public class Email
extends java.lang.Object
Typical use:
Email email = ConfigurationManager.getEmail(name);
email.addRecipient("foo@bar.com");
email.addArgument("John");
email.addArgument("On the Testing of DSpace");
email.send();
name is the name of an email template in
dspace-dir/config/emails/ (which also includes the subject.)
arg0 and arg1 are arguments to fill out the
message with.
Emails are formatted using java.text.MessageFormat.
Additionally, comment lines (starting with '#') are stripped, and if a line
starts with "Subject:" the text on the right of the colon is used for the
subject line. For example:
# This is a comment line which is stripped
#
# Parameters: {0} is a person's name
# {1} is the name of a submission
#
Subject: Example e-mail
Dear {0},
Thank you for sending us your submission "{1}".
If the example code above was used to send this mail, the resulting mail
would have the subject Example e-mail and the body would be:
Dear John,
Thank you for sending us your submission "On the Testing of DSpace".
Note that parameters like {0} cannot be placed in the subject
of the e-mail; they won't get filled out.
| Modifier and Type | Class and Description |
|---|---|
class |
Email.InputStreamDataSource |
| Constructor and Description |
|---|
Email()
Create a new email message.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addArgument(java.lang.Object arg)
Fill out the next argument in the template
|
void |
addAttachment(java.io.File f,
java.lang.String name) |
void |
addAttachment(java.io.InputStream is,
java.lang.String name,
java.lang.String mimetype) |
void |
addRecipient(java.lang.String email)
Add a recipient
|
static Email |
getEmail(java.lang.String emailFile)
Get the template for an email message.
|
static void |
main(java.lang.String[] args)
Test method to send an email to check email server settings
|
void |
reset()
"Reset" the message.
|
void |
send()
Sends the email.
|
void |
setCharset(java.lang.String cs) |
void |
setContent(java.lang.String cnt)
Set the content of the message.
|
void |
setReplyTo(java.lang.String email)
Set the reply-to email address
|
void |
setSubject(java.lang.String s)
Set the subject of the message
|
public void addRecipient(java.lang.String email)
email - the recipient's email addresspublic void setContent(java.lang.String cnt)
addArgument will start. Comments and any
"Subject:" line must be stripped.cnt - the content of the messagepublic void setSubject(java.lang.String s)
s - the subject of the messagepublic void setReplyTo(java.lang.String email)
email - the reply-to email addresspublic void addArgument(java.lang.Object arg)
arg - the value for the next argumentpublic void addAttachment(java.io.File f,
java.lang.String name)
public void addAttachment(java.io.InputStream is,
java.lang.String name,
java.lang.String mimetype)
public void setCharset(java.lang.String cs)
public void reset()
public void send()
throws javax.mail.MessagingException,
java.io.IOException
javax.mail.MessagingException - if there was a problem sending the mail.java.io.IOExceptionpublic static Email getEmail(java.lang.String emailFile) throws java.io.IOException
java.text.MessageFormat.emailFile - full name for the email template, for example "/dspace/config/emails/register".java.io.IOException - if the template couldn't be found, or there was some other
error reading the templatepublic static void main(java.lang.String[] args)
args - Command line optionsCopyright © 2018 DuraSpace. All Rights Reserved.