Interface | Description |
---|---|
Message.RecipientType |
Class | Description |
---|---|
Address |
This class represents an Internet e-mail address using the syntax of RFC822.
|
BinaryContentHandler |
Implementation of DataContentHandler that handles MIME types handled as base64 encoded byte arrays.
It also handle Streams, reading from the input stream on demand to avoid excessive memory load. |
DataContentHandler |
Defines the basic interface for implementations of DataContentHandler.
|
DataHandler |
Maps a MIME type into an instance of a DataContentHandler.
|
Folder |
Folder is an abstract class that represents a folder for mail messages.
|
MailSession |
Used to store properties used by the messaging API.
|
Message |
This class represents a MIME style e-mail message.
|
Multipart |
Multipart is a container that holds multiple body parts.
|
Part |
This class represents a MIME body part, which are contained by Multipart objects.
|
POP3Folder |
A POP3 Folder (can only be "INBOX").
|
POP3Store |
A POP3 Message Store.
|
Service |
An abstract class that models a message store and its access protocol, for storing and retrieving messages.
|
SMTPSSLTransport |
This class implements the Transport abstract class using SMTP for message submission and transport over secure sockets.
|
SMTPTransport |
This class implements the Transport abstract class using SMTP for message submission and transport.
|
Store |
An abstract class that models a message store and its access protocol, for storing and retrieving messages.
|
TextContentHandler |
Implementation of DataContentHandler that handles textual (not encoded) MIME types.
|
Transport |
An abstract class that models a message transport.
|
Exception | Description |
---|---|
AddressException |
Thrown by the
Address constructor if the given string address is invalid. |
MessagingException |
Thrown when a write operation fails when sending a Message, or when an unexpected code is received from the remote
host.
|
MailSession session = MailSession.getDefaultInstance(); session.put(MailSession.SMTP_HOST, new Properties.Str("smtp.sample.com")); // SMTP host address session.put(MailSession.SMTP_PORT, new Properties.Int(25)); // unless noticed otherwise by the server, SMTP uses port 25 session.put(MailSession.SMTP_USER, new Properties.Str("[email protected]")); // usually the full e-mail address session.put(MailSession.SMTP_PASS, new Properties.Str("VerySecurePassword")); // e-mail account passwordSending a simple e-mail message:
Message myMessage = new Message(); // our new message myMessage.from = new Address("[email protected]", "Mr. Foo"); // the e-mail address I wan't to be visible to the recipient and a personal name. myMessage.addRecipient(RecipientType.TO, new Address("[email protected]", null)); // the recipient of the e-mail myMessage.subject = "Testing SMTP with authentication"; // e-mail subject myMessage.setText("This is just a test message"); // simple e-mail with plain text Transport.send(myMessage); // sends our message using the propert Transport for this Message, and the properties defined on the default MailSession.Sending an e-mail with attachments:
// text part Part textPart = new Part(); textPart.setText("Plain text"); // image part Part imagePart = new Part(); File image = new File("/myImage.png", File.READ_WRITE); // keep file open! imagePart.setContent(image, "image/png"); imagePart.fileName = "myImage.png"; // create the multiparts Multipart multipart = new Multipart(); multipart.addPart(textPart); multipart.addPart(imagePart); // create the message Message myMessage = new Message(); myMessage.setContent(multipart); myMessage.subject = "E-mail with attachment"; myMessage.from = new Address("[email protected]", "Someone name"); myMessage.addRecipient(Message.RecipientType.TO, new Address("[email protected]", "ToMe")); // send the message Transport.send(myMessage); // close the image file AFTER the message is sent image.close();Receive a message, and open the first one available.
MailSession session = MailSession.getDefaultInstance(); session.put(MailSession.POP3_HOST, new Properties.Str("pop3.sample.com")); session.put(MailSession.POP3_PORT, new Properties.Int(110)); session.put(MailSession.POP3_USER, new Properties.Str("[email protected]")); session.put(MailSession.POP3_PASS, new Properties.Str("VerySecurePassword")); Store store = MailSession.getDefaultInstance().getStore("pop3"); store.connect(); Folder folder = store.getFolder("INBOX"); folder.open(); int messageCount = folder.getMessageCount(); if (messageCount > 0) { Message msg = folder.getMessage(1); String msgContent = (String) msg.getContent(); if (msgContent != null) new MessageBox(msg.from.address, msgContent).popup(); } folder.close(true); store.close();