public class Email extends Object
Typical use:
Email email = new Email();
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(Object arg)
Fill out the next argument in the template
|
void |
addAttachment(File f,
String name) |
void |
addAttachment(InputStream is,
String name,
String mimetype) |
void |
addRecipient(String email)
Add a recipient
|
static Email |
getEmail(String emailFile)
Get the template for an email message.
|
static void |
main(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(String cs) |
void |
setContent(String cnt)
Set the content of the message.
|
void |
setReplyTo(String email)
Set the reply-to email address
|
void |
setSubject(String s)
Set the subject of the message
|
public void addRecipient(String email)
email - the recipient's email addresspublic void setContent(String cnt)
addArgument will start. Comments and any
"Subject:" line must be stripped.cnt - the content of the messagepublic void setSubject(String s)
s - the subject of the messagepublic void setReplyTo(String email)
email - the reply-to email addresspublic void addArgument(Object arg)
arg - the value for the next argumentpublic void addAttachment(InputStream is, String name, String mimetype)
public void setCharset(String cs)
public void reset()
public void send()
throws javax.mail.MessagingException,
IOException
javax.mail.MessagingException - if there was a problem sending the mail.IOException - if IO errorpublic static Email getEmail(String emailFile) throws IOException
java.text.MessageFormat.emailFile - full name for the email template, for example "/dspace/config/emails/register".IOException - if IO error
if the template couldn't be found, or there was some other
error reading the templatepublic static void main(String[] args)
args - Command line optionsCopyright © 2017 DuraSpace. All rights reserved.