transport.java revision 364
/*
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
*
* - Neither the name of Oracle nor the names of its
* contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
* IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import javax.activation.*;
/**
* transport is a simple program that creates a message, explicitly
* retrieves a Transport from the session based on the type of the
* address (it's InternetAddress, so SMTP will be used) and sends
* the message.
*
* usage: <code>java transport <i>"toaddr1[, toaddr2]*" from smtphost
* true|false</i></code><br>
* where <i>to</i> and <i>from</i> are the destination and
* origin email addresses, respectively, and <i>smtphost</i>
* is the hostname of the machine that has the smtp server
* running. The <i>to</i> addresses can be either a single email
* address or a comma-separated list of email addresses in
* quotes, i.e. "joe@machine, jane, max@server.com"
* The last parameter either turns on or turns off
* debugging during sending.
*
* @author Max Spivak
*/
// parse the arguments
boolean debug = false;
usage();
return;
} else {
debug = true;
debug = false;
} else {
usage();
return;
}
// parse the destination addresses
try {
} catch (AddressException aex) {
return;
}
}
// create some properties and get a Session
}
public transport() {}
try {
// create a message
msg.saveChanges();
// get the smtp transport for the address
// register ourselves as listener for ConnectionEvents
// and TransportEvents
trans.addConnectionListener(this);
trans.addTransportListener(this);
// connect the transport
// send the message
// give the EventQueue enough time to fire its events
} catch (MessagingException mex) {
// give the EventQueue enough time to fire its events
do {
if (ex instanceof SendFailedException) {
}
if (validUnsent != null) {
}
}
}
if (ex instanceof MessagingException)
else
} finally {
try {
// close the transport
}
}
// implement ConnectionListener interface
public void opened(ConnectionEvent e) {
}
public void disconnected(ConnectionEvent e) {}
public void closed(ConnectionEvent e) {
}
// implement TransportListener interface
public void messageDelivered(TransportEvent e) {
}
}
public void messageNotDelivered(TransportEvent e) {
}
}
public void messagePartiallyDelivered(TransportEvent e) {
}
}
}
}
private static void usage() {
"usage: java transport \"<to1>[, <to2>]*\" <from> <smtp> true|false");
"example: java transport \"joe@machine, jane\" senderaddr smtphost false");
}
}