Top Description Inners Fields Constructors Methods
org.apache.tools.ant.taskdefs.email

public Class EmailTask

extends Task
Class Inheritance
Known Direct Subclasses
org.apache.tools.ant.taskdefs.optional.net.MimeMail, org.apache.tools.ant.taskdefs.SendEmail
Imports
java.io.File, java.util.StringTokenizer, .Vector, org.apache.tools.ant.BuildException, .Project, .Task, org.apache.tools.ant.types.EnumeratedAttribute, .FileSet, .Path, .Resource, org.apache.tools.ant.types.resources.FileProvider, .FileResource, org.apache.tools.ant.util.ClasspathUtils

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 and Inner Type Summary

Modifier and TypeClass and Description
public static class
EmailTask.Encoding

Enumerates the encoding constants.

Field Summary

Modifier and TypeField and Description
private Path
attachments

file list

public static final String
AUTO

Constant to show that the best available mailer should be used.

private Vector<EmailAddress>
bccList

BCC (Blind Carbon Copy) recipients

private Vector<EmailAddress>
ccList

CC (Carbon Copy) recipients

private String
charset

Character set for MimeMailer

private String
private boolean
failOnError

failure flag

private EmailAddress
from

sender

private Vector<Header>
headers

generic headers

private String
host

host running SMTP

private boolean
ignoreInvalidRecipients

ignore invalid recipients?

private boolean
private Message
message

any text

private String
private String
public static final String
MIME

Constant to allow the Mime mailer to be requested

private String
password

Password for SMTP auth

public static final String
PLAIN

Constant to allow the plaintext mailer to be requested

private Integer
private Vector<EmailAddress>
replyToList

replyto

private static final int
private boolean
ssl

indicate if the user wishes SSL-TLS

private boolean
starttls

indicate if the user wishes support for STARTTLS

private String
subject

subject field

private Vector<EmailAddress>
toList

TO recipients

private String
user

User for SMTP auth

public static final String
UU

Constant to allow the UU mailer to be requested

Inherited from org.apache.tools.ant.Task:
targettaskNametaskTypewrapper

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
addBcc(EmailAddress
The email address.
address
)

Add a "bcc" address element.

public void
addCc(EmailAddress
The email address.
address
)

Add a "cc" address element.

public void
addFileset(FileSet
The fileset.
fs
)

Add a set of files (nested fileset attribute).

public void
addFrom(EmailAddress
The address to send from.
address
)

Add a from address element.

public void
addMessage(Message
The message object.
message
)

Add a message element.

public void
addReplyTo(EmailAddress
The address to reply to.
address
)

Add a replyto address element.

public void
addTo(EmailAddress
An email address.
address
)

Add a to address element.

public Path

Returns:

the path to be configured.
createAttachments
()

Creates a Path as container for attachments.

public Header

Returns:

a Header instance.
createHeader
()

Create a nested header element.

public void
execute()

Overrides org.apache.tools.ant.Task.execute.

Send an email.
public String

Returns:

Charset of mail message.
getCharset
()

Returns the character set of mail message.

public boolean

Returns:

Identifies whether file names should be included.
getIncludeFileNames
()

Get whether file names should be included.

private String
private void
public void
setBccList(String
comma separated list of addresses.
list
)

Shorthand to set the "bcc" address element.

public void
setCcList(String
Comma separated list of addresses.
list
)

Shorthand to set the "cc" address element.

public void
setCharset(String
the character encoding to use.
charset
)

Sets the character set of mail message.

public void
setEnableStartTLS(boolean
boolean; if true STARTTLS will be supported.
b
)

Set whether to allow authentication to switch to a TLS connection via STARTTLS.

public void
setEncoding(EmailTask.Encoding
The encoding (one of AUTO, MIME, UU, PLAIN).
encoding
)

Set the preferred encoding method.

public void
setFailOnError(boolean
The new FailOnError value.
failOnError
)

Set whether BuildExceptions should be passed back to the core.

public void
setFiles(String
Comma-separated list of files.
filenames
)

Set the list of files to be attached.

public void
setFrom(String
The address to send mail from.
address
)

Shorthand to set the from address element.

public void
setIgnoreInvalidRecipients(boolean
boolean
b
)

Whether invalid recipients should be ignored (but a warning will be logged) instead of making the task fail.

public void
setIncludefilenames(boolean
Whether to include filenames in the text of the message.
includeFileNames
)

Set whether to include filenames.

public void
setMailhost(String
The host to connect to.
host
)

Set the host.

public void
setMailport(int
The port to use.
port
)

Set the mail server port.

public void
setMessage(String
Message body of this email.
message
)

Shorthand method to set the message.

public void
setMessageFile(File
The file from which to take the message.
file
)

Shorthand method to set the message from a file.

public void
setMessageFileInputEncoding(String
the name of the charset used
encoding
)

Sets the encoding to expect when reading the message from a file.

public void
setMessageMimeType(String
The new MessageMimeType value.
type
)

Shorthand method to set type of the text message, text/plain by default but text/html or text/xml is quite feasible.

public void
setPassword(String
the String password.
password
)

Set the password for SMTP auth; this requires JavaMail.

public void
setReplyTo(String
The address to which replies should be directed.
address
)

Shorthand to set the replyto address element.

public void
setSSL(boolean
boolean; if true SSL will be used.
ssl
)

Set whether to send data over SSL.

public void
setSubject(String
Subject of this email.
subject
)

Set the subject line of the email.

public void
setToList(String
Comma-separated list of addresses.
list
)

Shorthand to set the "to" address element.

public void
setUser(String
the String username.
user
)

Set the user for SMTP auth; this requires JavaMail.

Inherited from org.apache.tools.ant.Task:
bindToOwnergetOwningTargetgetRuntimeConfigurableWrappergetTaskNamegetTaskTypegetWrapperhandleErrorFlushhandleErrorOutputhandleFlushhandleInputhandleOutputinitisInvalidloglogloglogmaybeConfigureperformreconfiguresetOwningTargetsetRuntimeConfigurableWrappersetTaskNamesetTaskType

Field Detail

attachmentsback to summary
private Path attachments

file list

AUTOback to summary
public static final String AUTO

Constant to show that the best available mailer should be used.

bccListback to summary
private Vector<EmailAddress> bccList

BCC (Blind Carbon Copy) recipients

ccListback to summary
private Vector<EmailAddress> ccList

CC (Carbon Copy) recipients

charsetback to summary
private String charset

Character set for MimeMailer

encodingback to summary
private String encoding
failOnErrorback to summary
private boolean failOnError

failure flag

fromback to summary
private EmailAddress from

sender

headersback to summary
private Vector<Header> headers

generic headers

hostback to summary
private String host

host running SMTP

ignoreInvalidRecipientsback to summary
private boolean ignoreInvalidRecipients

ignore invalid recipients?

includeFileNamesback to summary
private boolean includeFileNames
messageback to summary
private Message message

any text

messageFileInputEncodingback to summary
private String messageFileInputEncoding
messageMimeTypeback to summary
private String messageMimeType
MIMEback to summary
public static final String MIME

Constant to allow the Mime mailer to be requested

passwordback to summary
private String password

Password for SMTP auth

PLAINback to summary
public static final String PLAIN

Constant to allow the plaintext mailer to be requested

portback to summary
private Integer port
replyToListback to summary
private Vector<EmailAddress> replyToList

replyto

SMTP_PORTback to summary
private static final int SMTP_PORT
sslback to summary
private boolean ssl

indicate if the user wishes SSL-TLS

starttlsback to summary
private boolean starttls

indicate if the user wishes support for STARTTLS

subjectback to summary
private String subject

subject field

toListback to summary
private Vector<EmailAddress> toList

TO recipients

userback to summary
private String user

User for SMTP auth

UUback to summary
public static final String UU

Constant to allow the UU mailer to be requested

Constructor Detail

EmailTaskback to summary
public EmailTask()

Method Detail

addBccback to summary
public void addBcc(EmailAddress address)

Add a "bcc" address element.

Parameters
address:EmailAddress

The email address.

addCcback to summary
public void addCc(EmailAddress address)

Add a "cc" address element.

Parameters
address:EmailAddress

The email address.

addFilesetback to summary
public void addFileset(FileSet fs)

Add a set of files (nested fileset attribute).

Parameters
fs:FileSet

The fileset.

addFromback to summary
public void addFrom(EmailAddress address)

Add a from address element.

Parameters
address:EmailAddress

The address to send from.

addMessageback to summary
public void addMessage(Message message) throws BuildException

Add a message element.

Parameters
message:Message

The message object.

Exceptions
BuildException:
if a message has already been added.
addReplyToback to summary
public void addReplyTo(EmailAddress address)

Add a replyto address element.

Parameters
address:EmailAddress

The address to reply to.

Since
Ant 1.6
addToback to summary
public void addTo(EmailAddress address)

Add a to address element.

Parameters
address:EmailAddress

An email address.

createAttachmentsback to summary
public Path createAttachments()

Creates a Path as container for attachments. Supports any filesystem resource-collections that way.

Returns:Path

the path to be configured.

Since
Ant 1.7
createHeaderback to summary
public Header createHeader()

Create a nested header element.

Returns:Header

a Header instance.

executeback to summary
public void execute()

Overrides org.apache.tools.ant.Task.execute.

Send an email.

Annotations
@Override
getCharsetback to summary
public String getCharset()

Returns the character set of mail message.

Returns:String

Charset of mail message.

Since
Ant 1.6
getIncludeFileNamesback to summary
public boolean getIncludeFileNames()

Get whether file names should be included.

Returns:boolean

Identifies whether file names should be included.

getMailerImplementationback to summary
private String getMailerImplementation()
logBuildExceptionback to summary
private void logBuildException(String reason, BuildException e)
setBccListback to summary
public void setBccList(String list)

Shorthand to set the "bcc" address element.

Parameters
list:String

comma separated list of addresses.

setCcListback to summary
public void setCcList(String list)

Shorthand to set the "cc" address element.

Parameters
list:String

Comma separated list of addresses.

setCharsetback to summary
public void setCharset(String charset)

Sets the character set of mail message. Will be ignored if mimeType contains ....; Charset=... substring or encoding is not mime.

Parameters
charset:String

the character encoding to use.

Since
Ant 1.6
setEnableStartTLSback to summary
public void setEnableStartTLS(boolean b)

Set whether to allow authentication to switch to a TLS connection via STARTTLS.

Parameters
b:boolean

boolean; if true STARTTLS will be supported.

Since
Ant 1.8.0
setEncodingback to summary
public void setEncoding(EmailTask.Encoding encoding)

Set the preferred encoding method.

Parameters
encoding:EmailTask.Encoding

The encoding (one of AUTO, MIME, UU, PLAIN).

setFailOnErrorback to summary
public void setFailOnError(boolean failOnError)

Set whether BuildExceptions should be passed back to the core.

Parameters
failOnError:boolean

The new FailOnError value.

setFilesback to summary
public void setFiles(String filenames)

Set the list of files to be attached.

Parameters
filenames:String

Comma-separated list of files.

setFromback to summary
public void setFrom(String address)

Shorthand to set the from address element.

Parameters
address:String

The address to send mail from.

setIgnoreInvalidRecipientsback to summary
public void setIgnoreInvalidRecipients(boolean b)

Whether invalid recipients should be ignored (but a warning will be logged) instead of making the task fail.

Even with this property set to true the task will still fail if the mail couldn't be sent to any recipient at all.

Parameters
b:boolean

boolean

Since
Ant 1.8.0
setIncludefilenamesback to summary
public void setIncludefilenames(boolean includeFileNames)

Set whether to include filenames.

Parameters
includeFileNames:boolean

Whether to include filenames in the text of the message.

setMailhostback to summary
public void setMailhost(String host)

Set the host.

Parameters
host:String

The host to connect to.

setMailportback to summary
public void setMailport(int port)

Set the mail server port.

Parameters
port:int

The port to use.

setMessageback to summary
public void setMessage(String message)

Shorthand method to set the message.

Parameters
message:String

Message body of this email.

setMessageFileback to summary
public void setMessageFile(File file)

Shorthand method to set the message from a file.

Parameters
file:File

The file from which to take the message.

setMessageFileInputEncodingback to summary
public void setMessageFileInputEncoding(String encoding)

Sets the encoding to expect when reading the message from a file.

Will be ignored if the message has been specified inline.

Parameters
encoding:String

the name of the charset used

Since
Ant 1.9.4
setMessageMimeTypeback to summary
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:String

The new MessageMimeType value.

setPasswordback to summary
public void setPassword(String password)

Set the password for SMTP auth; this requires JavaMail.

Parameters
password:String

the String password.

Since
Ant 1.6
setReplyToback to summary
public void setReplyTo(String address)

Shorthand to set the replyto address element.

Parameters
address:String

The address to which replies should be directed.

Since
Ant 1.6
setSSLback to summary
public void setSSL(boolean ssl)

Set whether to send data over SSL.

Parameters
ssl:boolean

boolean; if true SSL will be used.

Since
Ant 1.6
setSubjectback to summary
public void setSubject(String subject)

Set the subject line of the email.

Parameters
subject:String

Subject of this email.

setToListback to summary
public void setToList(String list)

Shorthand to set the "to" address element.

Parameters
list:String

Comma-separated list of addresses.

setUserback to summary
public void setUser(String user)

Set the user for SMTP auth; this requires JavaMail.

Parameters
user:String

the String username.

Since
Ant 1.6
org.apache.tools.ant.taskdefs.email back to summary

public Class EmailTask.Encoding

extends EnumeratedAttribute
Class Inheritance

Enumerates the encoding constants.

Field Summary

Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
value

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public String[]

Returns:

a list of valid entries
getValues
()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

finds the valid encoding values
Inherited from org.apache.tools.ant.types.EnumeratedAttribute:
containsValuegetIndexgetInstancegetValueindexOfValuesetValuetoString

Constructor Detail

Encodingback to summary
public Encoding()

Method Detail

getValuesback to summary
public String[] getValues()

Implements abstract org.apache.tools.ant.types.EnumeratedAttribute.getValues.

finds the valid encoding values

Returns:String[]

a list of valid entries

Annotations
@Override