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
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
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 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"));
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 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
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
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
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
Sun maintains a FAQ on JavaMail at http://java.sun.com/products/javamail/FAQ.html.
According to the license that comes with the distribution, you are free to redistribute the unmodified JAR files.
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
There is no support for this built into the API. According to Sun's JavaMail FAQ: The JavaMail API does not include any facilities for adding, removing, or changing user accounts. There are no st...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
When you add a recipient InternetAddress, use Message.RecipientType.BCC: String addressString = "firstname.lastname@example.org"; InternetAddress bcc = new InternetAddress(addressString); me...more