from = InternetAddress.getLocalAddress(session).getAddress();
}
}
if (from == null || from.length() == 0) {
throw new MessagingException("no FROM address");
}
StringBuffer command = new StringBuffer();
// start building up the command
command.append("MAIL FROM: ");
command.append(fixEmailAddress(from));
// does this server support Delivery Status Notification? Then we may
// need to add some extra to the command.
if (supportsExtension("DSN")) {
String returnNotification = null;
// the return notification stuff might be set as value on the
// message object itself.
if (message instanceof SMTPMessage) {
// we need to convert the option into a string value.
switch (((SMTPMessage) message).getReturnOption()) {
case SMTPMessage.RETURN_FULL:
returnNotification = "FULL";
break;
case SMTPMessage.RETURN_HDRS:
returnNotification = "HDRS";
break;
}
}
// if not obtained from the message object, it can also be set as a
// property.
if (returnNotification == null) {
// the DSN value is set by yet another property.
returnNotification = getProtocolProperty(MAIL_SMTP_DSN_RET);
}
// if we have a target, add the notification stuff to our FROM
// command.
if (returnNotification != null) {
command.append(" RET=");
command.append(returnNotification);
}
}
// if this server supports AUTH and we have submitter information, then
// we also add the
// "AUTH=" keyword to the MAIL FROM command (see RFC 2554).
if (supportsExtension("AUTH")) {
String submitter = null;
// another option that can be specified on the message object.
if (message instanceof SMTPMessage) {
submitter = ((SMTPMessage) message).getSubmitter();
}
// if not part of the object, try for a propery version.
if (submitter == null) {
// we only send the extra keyword is a submitter is specified.
submitter = getProtocolProperty(MAIL_SMTP_SUBMITTER);
}
// we have one...add the keyword, plus the submitter info in xtext
// format (defined by RFC 1891).
if (submitter != null) {
command.append(" AUTH=");
try {
// add this encoded
command.append(new String(XText.encode(submitter.getBytes("US-ASCII"))));
} catch (UnsupportedEncodingException e) {
throw new MessagingException("Invalid submitter value " + submitter);
}
}
}
String extension = null;