JavaMail Section Index | Page 21
If my mail server requires authentication to send messages, how do I set my username/password through the JavaMail API so I don't get a 'javax.mail.SendFailedException: 550 Relaying is prohibited' error?
When you connect to the Transport you can pass a username and password:
Transport transport =
session.getTransport("smtp");
transport.connect(
host, username, password);
Unfortunate...more
Where can I get the source code for the JavaMail classes?
The source for Sun's reference implementation of the JavaMail API is available as part of the J2EE 1.2 Sun Community Source Licensing release, available from http://www.sun.com/software/communitys...more
How do I encode the string that I want to send so that the message is mail safe?
When you call setText(message) on the MimePart/MimeMessage this will encode the string for you using the platform's default character set. If you know the character set, you can call setText(messa...more
How do I store messages locally using JavaMail?
The JavaMail API provides the core interfaces for working with many different types of providers. Sun provides implementations of SMTP and IMAP with the JavaMail implementation and freely offers a...more
How do I set up a default mime type for unknown file types using MimetypesFileTypeMap? At present when sending a message with an attached file of unknown file type a NullPointerException is thrown.
Just create a new map and ask:
MimetypesFileTypeMap mmp = new MimetypesFileTypeMap();
System.out.println(mmp.getContentType("d:
ajeshlbc.jpg"));
How can I use an Authenticator to prompt for username and password when reading mail from a IMAP/POP server?
Keep in mind that the Authenticator in JavaMail is different than the one in the java.net package. To use the javax.mail.Authenticator, the basic process to connect to the Store is as follows:
//...more
Where do I place the JAR files so that I can use JavaMail from JSP?
Using the JavaMail API from JSP pages requires the JavaMail and JavaBeans Activation Framework JAR files (mail.jar and activation.jar respectively) to be in the CLASSPATH for the Java runtime of y...more
How do I send an HTML content message through the JavaMail API?
First create a String object containg the HTML text for the message. Then use setContent() to set the message content to a specific content-type. For example :
String msgText = getHtmlMessageText(...more
How can I incorporate mail facilities into JSP pages?
Why, by using the JavaMail API of course... Your best bet is to create some JavaBeans that do all the work and access the beans from the JSP pages. You'll need to include the appropriate mail clas...more
Are there any other FAQs for JavaMail?
Sun maintains a FAQ on JavaMail at http://java.sun.com/products/javamail/FAQ.html.
What are the distribution limitations of Sun's reference implementation?
According to the license that comes with the distribution, you are free to redistribute the unmodified JAR files.
How do you find out the text character set in the message body?
You should find this in the ContentType of the part. If you're lucky, it will be present as something like "text/plain; charset=foobar". However, I don't believe this is required.more
How do I use BCC to hide recipient addresses?
When you add a recipient InternetAddress, use Message.RecipientType.BCC:
String addressString =
"bill@microsoft.com";
InternetAddress bcc =
new InternetAddress(addressString);
me...more
How do I efficiently send a bulk mailing, where I want to send mail out to lots of recipients, not all on the same TO/CC/BCC line?
Get the necessary Transport object and call sendMessage() on it for each message. Be sure to set/change recipients between calls.
Message message = ...;
Transport t = session.getTransport("...more
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