Methods Summary |
---|
public void | addCCRecipient(java.lang.String message_cc)
// CC Address
InternetAddress ccAddress = new InternetAddress(message_cc);
mesg.addRecipient(Message.RecipientType.CC, ccAddress);
|
public void | addRecipient(java.lang.String message_recip)
// TO Address
InternetAddress toAddress = new InternetAddress(message_recip);
mesg.addRecipient(Message.RecipientType.TO, toAddress);
|
public static void | main(java.lang.String[] args)Driver to parse options and control Sender
try {
Sender2 sm = new Sender2();
GetOpt go = new GetOpt("c:f:t:s:");
char c;
while ((c =go.getopt(args)) != 0) {
switch(c) {
case 'h":
// XXX sm.setMailHost();
sm.props.put("mail.smtp.host", go.optarg());
break;
case 't":
sm.addRecipient(go.optarg());
break;
case 'c":
sm.addCCRecipient(go.optarg());
break;
case 'f":
sm.setFrom(go.optarg());
break;
case 's":
sm.setSubject(go.optarg());
break;
default:
System.err.println("Unknown option character " + c);
usage(1);
}
}
if (go.getOptInd() == args.length) {
sm.sendFile("(standard input)");
} else for (int i=go.getOptInd(); i<args.length; i++)
sm.sendFile(args[i]);
} catch (MessagingException e) {
System.err.println(e);
}
|
public void | sendFile(java.lang.String fileName)
// Now the message body.
setBody(message_body);
sendFile();
|
public void | sendFile()Send the file with no filename, assuming you've already called
the setBody() method.
try {
// Finally, send the message! (use static Transport method)
Transport.send(mesg);
} catch (MessagingException ex) {
while ((ex = (MessagingException)ex.getNextException()) != null) {
ex.printStackTrace();
}
}
|
public void | setBody(java.lang.String message_body)Set the message body.
mesg.setText(message_body);
// XXX I18N: use setText(msgText.getText(), charset)
|
public void | setFrom(java.lang.String sender)
// From Address - this should come from a Properties...
mesg.setFrom(new InternetAddress(sender));
|
public void | setSubject(java.lang.String message_subject)
// The Subject
mesg.setSubject(message_subject);
|
protected static void | usage(int returnValue)Stub for providing help on usage
You can write a longer help than this, certainly.
System.err.println("Usage: Sender2 [-t to][-c cc][-f from][-s subj] file ...");
System.exit(returnValue);
|