JavaMail Section Index | Page 22
Can I get a trace of the actual SMTP commands sent to the mail server?
Yes. For your mail session, set the debug property to true: session.setDebug(true).
How can I reply to a message?
Calling the reply() method of the Message class will create a properly created header for your reply. If you wish to include the content of the original message, you'll have to include it yourself.more
How do I include a text name with the from header, besides just an email address?
The message.setFrom(new InternetAddress(from)); line is suffcient to include a name with the line, where from would be a string like ""Bill Clinton" <president@whitehouse.gov>...more
How secure is JavaMail?
If you are worried about security with your mail, you would need to get an S/MIME provider to work with JavaMail. This would include support for email signing and encryption. The Phaos S/MIME tool...more
How can I send an attachment using sun.net.smtp.SmtpClient?
From the looks of the public API:
public class sun.net.smtp.SmtpClient
extends sun.net.TransferProtocolClient {
public void closeServer()
throws IOException;
public void to(String) ...more
How do I send email with attachments using the JavaMail API?
Here is the code to send an attachment:
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;
public class AttachExample {
public static vo...more
How do I encrypt the body text of an email? Can I use PGP in conjunction with JavaMail?
If you are an US/Canadian you can use the JCE (Java Cryptographic Extension), available from Sun (http://java.sun.com/products/jce/). Remember that after encryption, you will get binary output, so...more
How do I deal with attachments when reading messages?
When a message includes an attachment, the content of the message will be Multipart [message.getContent() instanceof Multipart] instead of Part. You'll need to get each part of the Multipart and p...more
How does one determine the number of new mail messages in a POP account?
POP servers do not support flags like read or answered. It is only meant for forwarding messages to an appropriate client store. IMAP is one such protocol that will report flags where you can find...more
Where can I find an NNTP provider for the JavaMail API?
Knife (http://bluezoo.org/knife/) is a free mail and user news agent that uses the JavaMail API and comes with a POP3 and NNTP provider. It is distributed under the GNU General Public License. A s...more
How can I find out how many messages are waiting to be read on my IMAP/POP server?
The getMessageCount() method of Folder reports this information. The following program demonstrates.
import javax.mail.*;
import javax.mail.internet.*;
public class GetCountExample {
public s...more
How does JavaMail deal with queuing mail when the initial attempt fails?
It doesn't. A javax.mail.MessagingException will be thrown if there is a failure in sending the message. It is your responsibility to try to recover. The MessagingException class maintains a linke...more
How do you send mail using the JavaMail API through a proxy server?
How do you send mail using the JavaMail API through a proxy server?
I have connected to the net through a proxy server and I also have a firewall installed. When I try to execute demo programs give...more
How can I read a mail message from my mail server?
The Message objects include writeTo() method. All you have to do is specify a stream to write to. The following program demonstrates this:
import java.io.*;
import java.util.Properties;
import ja...more
How do you delete a message from the mail server?
The basic process of deleting a message is to call setFlag() on the message and set the Flags.Flag.DELETED flag to true.
message.setFlag(Flags.Flag.DELETED, true);
Then, when you close the folde...more