org.apache.tools.ant.taskdefs.email

Class EmailTask

Implemented Interfaces:
Cloneable
Known Direct Subclasses:
MimeMail, SendEmail

public class EmailTask
extends Task

A task to send SMTP email. This is a refactoring of the SendMail and MimeMail tasks such that both are within a single task.
Since:
Ant 1.5

Nested Class Summary

static class
EmailTask.Encoding
Enumerates the encoding constants.

Field Summary

static String
AUTO
Constant to show that the best available mailer should be used.
static String
MIME
Constant to allow the Mime mailer to be requested
static String
PLAIN
Constant to allow the plaintext mailer to be requested
static String
UU
Constant to allow the UU mailer to be requested

Fields inherited from class org.apache.tools.ant.Task

target, taskName, taskType, wrapper

Fields inherited from class org.apache.tools.ant.ProjectComponent

description, location, project

Method Summary

void
addBcc(EmailAddress address)
Add a "bcc" address element.
void
addCc(EmailAddress address)
Add a "cc" address element.
void
addFileset(FileSet fs)
Add a set of files (nested fileset attribute).
void
addFrom(EmailAddress address)
Add a from address element.
void
addMessage(Message message)
Add a message element.
void
addReplyTo(EmailAddress address)
Add a replyto address element.
void
addTo(EmailAddress address)
Add a to address element.
Path
createAttachments()
Creates a Path as container for attachments.
Header
createHeader()
Create a nested header element.
void
execute()
Send an email.
String
getCharset()
Returns the character set of mail message.
boolean
getIncludeFileNames()
Get whether file names should be included.
void
setBccList(String list)
Shorthand to set the "bcc" address element.
void
setCcList(String list)
Shorthand to set the "cc" address element.
void
setCharset(String charset)
Sets the character set of mail message.
void
setEncoding(EmailTask.Encoding encoding)
Set the preferred encoding method.
void
setFailOnError(boolean failOnError)
Set whether BuildExceptions should be passed back to the core.
void
setFiles(String filenames)
Set the list of files to be attached.
void
setFrom(String address)
Shorthand to set the from address element.
void
setIncludefilenames(boolean includeFileNames)
Set whether to include filenames.
void
setMailhost(String host)
Set the host.
void
setMailport(int port)
Set the mail server port.
void
setMessage(String message)
Shorthand method to set the message.
void
setMessageFile(File file)
Shorthand method to set the message from a file.
void
setMessageMimeType(String type)
Shorthand method to set type of the text message, text/plain by default but text/html or text/xml is quite feasible.
void
setPassword(String password)
Set the password for SMTP auth; this requires JavaMail.
void
setReplyTo(String address)
Shorthand to set the replyto address element.
void
setSSL(boolean ssl)
Set whether to send data over SSL.
void
setSubject(String subject)
Set the subject line of the email.
void
setToList(String list)
Shorthand to set the "to" address element.
void
setUser(String user)
Set the user for SMTP auth; this requires JavaMail.

Methods inherited from class org.apache.tools.ant.Task

bindToOwner, execute, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType

Methods inherited from class org.apache.tools.ant.ProjectComponent

clone, getDescription, getLocation, getProject, log, log, setDescription, setLocation, setProject

Field Details

AUTO

public static final String AUTO
Constant to show that the best available mailer should be used.

MIME

public static final String MIME
Constant to allow the Mime mailer to be requested

PLAIN

public static final String PLAIN
Constant to allow the plaintext mailer to be requested

UU

public static final String UU
Constant to allow the UU mailer to be requested

Method Details

addBcc

public void addBcc(EmailAddress address)
Add a "bcc" address element.
Parameters:
address - The email address.

addCc

public void addCc(EmailAddress address)
Add a "cc" address element.
Parameters:
address - The email address.

addFileset

public void addFileset(FileSet fs)
Add a set of files (nested fileset attribute).
Parameters:
fs - The fileset.

addFrom

public void addFrom(EmailAddress address)
Add a from address element.
Parameters:
address - The address to send from.

addMessage

public void addMessage(Message message)
            throws BuildException
Add a message element.
Parameters:
message - The message object.
Throws:
BuildException - if a message has already been added.

addReplyTo

public void addReplyTo(EmailAddress address)
Add a replyto address element.
Parameters:
address - The address to reply to.
Since:
Ant 1.6

addTo

public void addTo(EmailAddress address)
Add a to address element.
Parameters:
address - An email address.

createAttachments

public Path createAttachments()
Creates a Path as container for attachments. Supports any filesystem resource-collections that way.
Returns:
the path to be configured.
Since:
Ant 1.7

createHeader

public Header createHeader()
Create a nested header element.
Returns:
a Header instance.

execute

public void execute()
Send an email.
Overrides:
execute in interface Task

getCharset

public String getCharset()
Returns the character set of mail message.
Returns:
Charset of mail message.
Since:
Ant 1.6

getIncludeFileNames

public boolean getIncludeFileNames()
Get whether file names should be included.
Returns:
Identifies whether file names should be included.

setBccList

public void setBccList(String list)
Shorthand to set the "bcc" address element.
Parameters:
list - comma separated list of addresses.

setCcList

public void setCcList(String list)
Shorthand to set the "cc" address element.
Parameters:
list - Comma separated list of addresses.

setCharset

public void setCharset(String charset)
Sets the character set of mail message. Will be ignored if mimeType contains ....; Charset=... substring or encoding is not a mime.
Parameters:
charset - the character encoding to use.
Since:
Ant 1.6

setEncoding

public void setEncoding(EmailTask.Encoding encoding)
Set the preferred encoding method.
Parameters:
encoding - The encoding (one of AUTO, MIME, UU, PLAIN).

setFailOnError

public void setFailOnError(boolean failOnError)
Set whether BuildExceptions should be passed back to the core.
Parameters:
failOnError - The new FailOnError value.

setFiles

public void setFiles(String filenames)
Set the list of files to be attached.
Parameters:
filenames - Comma-separated list of files.

setFrom

public void setFrom(String address)
Shorthand to set the from address element.
Parameters:
address - The address to send mail from.

setIncludefilenames

public void setIncludefilenames(boolean includeFileNames)
Set whether to include filenames.
Parameters:
includeFileNames - Whether to include filenames in the text of the message.

setMailhost

public void setMailhost(String host)
Set the host.
Parameters:
host - The host to connect to.

setMailport

public void setMailport(int port)
Set the mail server port.
Parameters:
port - The port to use.

setMessage

public void setMessage(String message)
Shorthand method to set the message.
Parameters:
message - Message body of this email.

setMessageFile

public void setMessageFile(File file)
Shorthand method to set the message from a file.
Parameters:
file - The file from which to take the message.

setMessageMimeType

public void setMessageMimeType(String type)
Shorthand method to set type of the text message, text/plain by default but text/html or text/xml is quite feasible.
Parameters:
type - The new MessageMimeType value.

setPassword

public void setPassword(String password)
Set the password for SMTP auth; this requires JavaMail.
Parameters:
password - the String password.
Since:
Ant 1.6

setReplyTo

public void setReplyTo(String address)
Shorthand to set the replyto address element.
Parameters:
address - The address to which replies should be directed.
Since:
Ant 1.6

setSSL

public void setSSL(boolean ssl)
Set whether to send data over SSL.
Parameters:
ssl - boolean; if true SSL will be used.
Since:
Ant 1.6

setSubject

public void setSubject(String subject)
Set the subject line of the email.
Parameters:
subject - Subject of this email.

setToList

public void setToList(String list)
Shorthand to set the "to" address element.
Parameters:
list - Comma-separated list of addresses.

setUser

public void setUser(String user)
Set the user for SMTP auth; this requires JavaMail.
Parameters:
user - the String username.
Since:
Ant 1.6