FileDocCategorySizeDatePackage
SMTPMessage.javaAPI DocJavaMail 1.4.311382Tue Nov 17 10:38:12 GMT 2009com.sun.mail.smtp

SMTPMessage

public class SMTPMessage extends MimeMessage
This class is a specialization of the MimeMessage class that allows you to specify various SMTP options and parameters that will be used when this message is sent over SMTP. Simply use this class instead of MimeMessage and set SMTP options using the methods on this class.

See the com.sun.mail.smtp package documentation for further information on the SMTP protocol provider.

author
Bill Shannon
see
javax.mail.internet.MimeMessage

Fields Summary
public static final int
NOTIFY_NEVER
Never notify of delivery status
public static final int
NOTIFY_SUCCESS
Notify of delivery success
public static final int
NOTIFY_FAILURE
Notify of delivery failure
public static final int
NOTIFY_DELAY
Notify of delivery delay
public static final int
RETURN_FULL
Return full message with delivery status notification
public static final int
RETURN_HDRS
Return only message headers with delivery status notification
private static final String[]
returnOptionString
private String
envelopeFrom
private int
notifyOptions
private int
returnOption
private boolean
sendPartial
private boolean
allow8bitMIME
private String
submitter
private String
extension
Constructors Summary
public SMTPMessage(Session session)
Default constructor. An empty message object is created. The headers field is set to an empty InternetHeaders object. The flags field is set to an empty Flags object. The modified flag is set to true.

	// extensions to use with MAIL command

                                            
       
	super(session);
    
public SMTPMessage(Session session, InputStream is)
Constructs an SMTPMessage by reading and parsing the data from the specified MIME InputStream. The InputStream will be left positioned at the end of the data for the message. Note that the input stream parse is done within this constructor itself.

param
session Session object for this message
param
is the message input stream
exception
MessagingException

	super(session, is);
    
public SMTPMessage(MimeMessage source)
Constructs a new SMTPMessage with content initialized from the source MimeMessage. The new message is independent of the original.

Note: The current implementation is rather inefficient, copying the data more times than strictly necessary.

param
source the message to copy content from
exception
MessagingException

	super(source);
    
Methods Summary
public booleangetAllow8bitMIME()
Is use of the 8BITMIME extension is allowed?

return
allow 8-bit flag

	return allow8bitMIME;
    
java.lang.StringgetDSNNotify()
Return notification options as an RFC 1891 string. Returns null if no options set.

	if (notifyOptions == 0)
	    return null;
	if (notifyOptions == NOTIFY_NEVER)
	    return "NEVER";
	StringBuffer sb = new StringBuffer();
	if ((notifyOptions & NOTIFY_SUCCESS) != 0)
	    sb.append("SUCCESS");
	if ((notifyOptions & NOTIFY_FAILURE) != 0) {
	    if (sb.length() != 0)
		sb.append(',");
	    sb.append("FAILURE");
	}
	if ((notifyOptions & NOTIFY_DELAY) != 0) {
	    if (sb.length() != 0)
		sb.append(',");
	    sb.append("DELAY");
	}
	return sb.toString();
    
java.lang.StringgetDSNRet()
Return return option as an RFC 1891 string. Returns null if no option set.

	return returnOptionString[returnOption];
    
public java.lang.StringgetEnvelopeFrom()
Return the envelope From address.

return
the envelope From address, or null if not set

	return envelopeFrom;
    
public java.lang.StringgetMailExtension()
Gets the extension string to use with the MAIL command.

return
the extension string
since
JavaMail 1.3.2

	return extension;
    
public intgetNotifyOptions()
Get notification options. Returns zero if no options set.

return
notification options

	return notifyOptions;
    
public intgetReturnOption()
Return return option. Returns zero if no option set.

return
return option

	return returnOption;
    
public booleangetSendPartial()
Send message if some addresses are invalid?

return
send partial flag

	return sendPartial;
    
public java.lang.StringgetSubmitter()
Gets the submitter to be used for the RFC 2554 AUTH= value in the MAIL FROM command.

return
the name of the submitter.

	return submitter;
    
public voidsetAllow8bitMIME(boolean allow)
If set to true, and the server supports the 8BITMIME extension, text parts of this message that use the "quoted-printable" or "base64" encodings are converted to use "8bit" encoding if they follow the RFC 2045 rules for 8bit text.

If true, overrides the mail.smtp.allow8bitmime property.

param
allow allow 8-bit flag

	allow8bitMIME = allow;
    
public voidsetEnvelopeFrom(java.lang.String from)
Set the From address to appear in the SMTP envelope. Note that this is different than the From address that appears in the message itself. The envelope From address is typically used when reporting errors. See RFC 821 for details.

If set, overrides the mail.smtp.from property.

param
from the envelope From address

	envelopeFrom = from;
    
public voidsetMailExtension(java.lang.String extension)
Set the extension string to use with the MAIL command. The extension string can be used to specify standard SMTP service extensions as well as vendor-specific extensions. Typically the application should use the {@link com.sun.mail.smtp.SMTPTransport SMTPTransport} method {@link com.sun.mail.smtp.SMTPTransport#supportsExtension supportsExtension} to verify that the server supports the desired service extension. See RFC 1869 and other RFCs that define specific extensions.

For example:

if (smtpTransport.supportsExtension("DELIVERBY"))
smtpMsg.setMailExtension("BY=60;R");

since
JavaMail 1.3.2

	this.extension = extension;
    
public voidsetNotifyOptions(int options)
Set notification options to be used if the server supports Delivery Status Notification (RFC 1891). Either NOTIFY_NEVER or some combination of NOTIFY_SUCCESS, NOTIFY_FAILURE, and NOTIFY_DELAY.

If set, overrides the mail.smtp.dsn.notify property.

param
options notification options

	if (options < -1 || options >= 8)
	    throw new IllegalArgumentException("Bad return option");
	notifyOptions = options;
    
public voidsetReturnOption(int option)
Set return option to be used if server supports Delivery Status Notification (RFC 1891). Either RETURN_FULL or RETURN_HDRS.

If set, overrides the mail.smtp.dsn.ret property.

param
option return option

	if (option < 0 || option > RETURN_HDRS)
	    throw new IllegalArgumentException("Bad return option");
	returnOption = option;
    
public voidsetSendPartial(boolean partial)
If set to true, and this message has some valid and some invalid addresses, send the message anyway, reporting the partial failure with a SendFailedException. If set to false (the default), the message is not sent to any of the recipients if there is an invalid recipient address.

If true, overrides the mail.smtp.sendpartial property.

param
partial send partial flag

	sendPartial = partial;
    
public voidsetSubmitter(java.lang.String submitter)
Sets the submitter to be used for the RFC 2554 AUTH= value in the MAIL FROM command. Normally only used by a server that's relaying a message. Clients will typically not set a submitter. See RFC 2554 for details.

param
submitter the name of the submitter

	this.submitter = submitter;