org.dspace.core
Class Email

java.lang.Object
  extended by org.dspace.core.Email

public class Email
extends Object

Class representing an e-mail message, also used to send e-mails.

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.

Version:
$Revision: 4659 $
Author:
Robert Tansley, Jim Downing - added attachment handling code

Method Summary
 void addArgument(Object arg)
          Fill out the next argument in the template
 void addAttachment(File f, String name)
           
 void addRecipient(String email)
          Add a recipient
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 setReplyTo(String email)
          Set the reply-to email address
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

addRecipient

public void addRecipient(String email)
Add a recipient

Parameters:
email - the recipient's email address

setReplyTo

public void setReplyTo(String email)
Set the reply-to email address

Parameters:
email - the reply-to email address

addArgument

public void addArgument(Object arg)
Fill out the next argument in the template

Parameters:
arg - the value for the next argument

addAttachment

public void addAttachment(File f,
                          String name)

setCharset

public void setCharset(String cs)

reset

public void reset()
"Reset" the message. Clears the arguments and recipients, but leaves the subject and content intact.


send

public void send()
          throws javax.mail.MessagingException
Sends the email.

Throws:
javax.mail.MessagingException - if there was a problem sending the mail.

main

public static void main(String[] args)
Test method to send an email to check email server settings

Parameters:
args - Command line options


Copyright © 2010 DuraSpace. All Rights Reserved.