【文章內(nèi)容簡(jiǎn)介】
elimited list of addresses ? If strict is true, space delimited is prohibited ? AddressException indicates parsing failed (“, , false))。 Standard Accessors and Mutators ? public void setAddress(String) ? public void setPersonal(String) ? public String getPersonal() ? public String getAddress() EMail Message Classes ? : Abstract class representing an message ? : Interface implemented by Message class defining properties and content of mail messages ? : – Extends Message class and provides functionality to produce MIME messages – Most mon constructor: MimeMessage(Session session) ? Innerclass of Message ? Possible values: – TO – CC – BCC – NEWSGROUPS MimeMessage Header Methods Setting Recipients ? public void setRecipient( type, Address address) ? public void setRecipients( type, Address[] addresses) Adding Additional Recipients ? public void addRecipient( type, Address address) ? public void addrecipients( type, Address[] addresses) Getting Recipients ? public Address[] getRecipients( type) ? public Address[] getAllRecipients() Setting From Header ? public void setFrom() Sets from to default from property specified in Session properties ? public void setFrom(Address address) ? Public void addFrom(Address[] addresses) Adds one or more addresses to those already listed in the from header Getting From Header public Address[] getFrom() ReplyTo Header ? public void setReplyTo(Address[] addresses) ? public Address[] getReplyTo() Note that several methods use arrays of Addresses Subject Header ? public void setSubject(String subject) ? public String getSubject() Sent Date Header ? public void setSentDate(Date date) ? public Date getSentDate() Content of a SinglePart Message ? public void setText(String text) Defaults to ASCII ? public void setText(String text, String charset) Used for nonASCII messages or to improve performance if there is a lot of text Note About Examples As always, you are encouraged to experiment with the examples that are provided. However, you must make sure that you use your own address in the from, replyto, and to headers so as not to “spam” anyone. Example 1: Sends an message from one person to another import .*。 import 。 import 。 import 。 import .*。 import .*。 Email address class Properties class Directory containing abstract mail classes Inter classes createSession() public Session createSession() { Properties p = ()。 (, smtp)。 (,)。 Gets the default system properties Sets the transport protocol to SMTP and sets the appropriate SMTP host for CMU (,imap)。 (,)。 Session sess = (p)。 return sess。 } Instantiates a session using the new properties object Sets the store protocol to IMAP and sets the appropriate SMTP host for CMU (not really needed unless the application will read ) createMessage() public Message createMessage(Session sess) throws MessagingException{ Message mess = new MimeMessage(sess)。 Base exception class for Inter mail Default Constructor for a MimeMessage (new InterAddress())。 (, (, false))。 (Test)。 (This is a test of JavaMail39。s functionality.)。 (new Date())。 return mess。 } setRecipients(MessageRecipientType type, String address) main() public static void main(String[] args) { MessageSend send = new MessageSend()。 Session sess = ()。 try { Message mess = (sess