This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA
" + ""; messageBodyPart.setContent(htmlText, "text/html"); // Create a related multi-part to combine the parts MimeMultipart multipart = new MimeMultipart("related"); multipart.addBodyPart(messageBodyPart); // Create part for the image messageBodyPart = new MimeBodyPart(); // Fetch the image and associate to part DataSource fds = new FileDataSource(file); messageBodyPart.setDataHandler(new DataHandler(fds)); messageBodyPart.setHeader("Content-ID","<memememe>"); // Add part to multi-part " elements). Comments and alternative answers
multipart.addBodyPart(messageBodyPart); // Create 2nd part for the image messageBodyPart = new MimeBodyPart(); // Fetch the image and associate to part DataSource fds2 = new FileDataSource(file2); messageBodyPart.setDataHandler(new DataHandler(fds2)); messageBodyPart.setHeader("Content-ID","
Suggestion Author: Virgil Mocanu (http://www.jguru.com/guru/viewbio.jsp?EID=861598), Apr 30, 2002 I would suggest to set the multipart as "alternative" (i.e. MimeMultipart multipart = new MimeMultipart("alternative");) because this option will let you to add a plain/text version of the message. Using "related" and adding a plain/text message will make the mail client to display the plain/text version of message instead of the HTML. What is the disposition of a message? Location: http://www.jguru.com/faq/view.jsp?EID=750764 Created: Feb 7, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Content disposition is an optional header (Content-Disposition) that can be used for an entire message or each part of the message. It can be used to indicate a part is an attachment, but it is not the only way to indicate a part is an attachment. For additional information on disposition, you can read RFC 2183. After marking a message as deleted, is it possible to undo the deletion? Location: http://www.jguru.com/faq/view.jsp?EID=760799 Created: Feb 15, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Jeya Selliah (http://www.jguru.com/guru/viewbio.jsp?EID=743366 Messages aren't deleted until you expunge the folder. If you don't want to the messages deleted, call close() with a value of false, and/or don't call expunge().
Once you've closed the folder with close(true) or called expunge(), the message is gone. How reliably can JavaMail parse messages? Location: http://www.jguru.com/faq/view.jsp?EID=761125 Created: Feb 16, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Bob Dickinson of Brute Squad Labs wrote up an article that describes the reliableness of the API, along with a handful of problems he identified. What is folding? Location: http://www.jguru.com/faq/view.jsp?EID=764371 Created: Feb 19, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) According to RFC 822, folding is the process of splitting a header field into multiple lines. How do I fold a ParameterList? Location: http://www.jguru.com/faq/view.jsp?EID=764373 Created: Feb 19, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The default (no-arg) toString() method returns the list unfolded. If you need the list folded, you can pass an int into the toString() method to indicate folding should be done and how many character positions should be counted for where to start folding. How do I know about the SMTP and POP3 addresses of the mail service providers? Location: http://www.jguru.com/faq/view.jsp?EID=772830 Created: Feb 26, 2002 Modified: 2002-12-26 20:42:15.484 Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585) Question originally posed by Ananthalakshmi Subramaniyam (http://www.jguru.com/guru/viewbio.jsp?EID=768989 Not every service may provide POP3/IMAP/SMTP support. Even if so, they may choose to guard it for various reason. You need to contact a particular service provider for the details. How to get access to the mailbox where user id contains space in it? I got few mail users created with space char in it (MS Exchange and Lotus Notes both). While same code works for the mail users without space char in their name but it throws AuthenticationFailedException for the mail users with space char in their name Location: http://www.jguru.com/faq/view.jsp?EID=772832 Created: Feb 26, 2002 Author: Chandra Patni (http://www.jguru.com/guru/viewbio.jsp?EID=33585) Question originally posed by AK Sharma (http://www.jguru.com/guru/viewbio.jsp?EID=759200
For JavaMail 1.2, you don't have do anything for imap authentication if username contains white spaces. You should add double quotes around user name for InternetAddress and for client which doesn't do this automcatically. For example, an imap session using telnet on port 143 would be as follows. Client> a001 LOGIN "Chandra Patni" javaiscool Server> a001 OK LOGIN completed. Client> a002 SELECT INBOX Server> * 4 EXISTS * 0 RECENT * FLAGS (\Seen \Answered \Flagged \Deleted \Draft) * OK [PERMANENTFLAGS (\Seen \Answered \Flagged \Deleted \Draft)] * OK [UNSEEN 2] Is the first unseen message * OK [UIDVALIDITY 1803] UIDVALIDITY value. a002 OK [READ-WRITE] SELECT completed. Client> a003 LOGOUT However, the SMTP server seem to have problem with such addresses. I could not make sendmail/reply work. The following example connects to an Exchange server and creates a Message which is appended to INBOX. import java.io.*; import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class TestMail1 { public static void main (String args[]) throws Exception { String username = "Java Duke"; String password = "welcomeduke"; String host = "myimap.domain.com"; if(args.length == 3) { username = args[0]; password = args[1]; host = args[2]; } Session session = Session.getInstance(new Properties(), null); MimeMessage message = new MimeMessage(session); InternetAddress from = new InternetAddress("\"Java Duke\"@"+ host); InternetAddress to = new InternetAddress("\"Java Duke\"@"+ host); message.setFrom(from); message.addRecipient(Message.RecipientType.TO, to); message.setSubject("This message is just added"); message.setText("Welcome Duke"); Store store = session.getStore("imap"); store.connect(host, username, password); Folder folder = store.getFolder("INBOX"); folder.open(Folder.READ_WRITE); folder.appendMessages(new Message[] {message});
Message messages[] = folder.getMessages(); for (int i=0, n=messages.length; i
Lotus Domino R5 Supports IMAP Author: Venkat Subramanian (http://www.jguru.com/guru/viewbio.jsp?EID=418608), Mar 13, 2002 Lotus Domino R5 supports IMAP and seems to work decently with our JavaMail code. We do extensive Lotus Email processing with JavaMail, and the system seems to be holding on well. There are couple of implementation bugs in Lotus like Copying email in the same Folder does not generate MessageCount event on it etc...
See my posts in this board on it. Re: Lotus Domino R5 Supports IMAP Author: JOnathan Chapman (http://www.jguru.com/guru/viewbio.jsp?EID=767315), Mar 26, 2002 Thanks for your reply. We have enabled IMAP on our R5 server and we can connect and receive messages using JavaMail. However, if there are lines in the body of the message longer than 72 characters, then the line gets split at the first space before the 72nd character, and a newline inserted. This is causing the processing of data in the message to fail. Have you come across this problem, and if so what can be done about it? Re[2]: Lotus Domino R5 Supports IMAP Author: Venkat Subramanian (http://www.jguru.com/guru/viewbio.jsp?EID=418608), Mar 27, 2002 We don't deal too much with the body of the message. So I haven't seen that problem. Thanks for informing anyway! We also work with MS Exchange 5.5 and 2000 - Exchange seems to fold subjects which inserts white spaces if the subject is long. Lotus Domino R5 IMAP server seem to degrade in performance as the mail database size grows in size. This is because the IMAP implementation depends extensively on Lotus views. { For example an IMAP 'EXISTS' which in turn becomes a java mail event gets delayed up to a minute as database size grows, typically it comes back within a second). Re[2]: Lotus Domino R5 Supports IMAP Author: Mario Fernandez (http://www.jguru.com/guru/viewbio.jsp?EID=848120), Apr 22, 2002 Hi everybody, I still have a problem with Lotus Notes R5 and JavaMail access. I´ve got a lot of Notes User with Notes Mail System. So now the problem is that in order to make JavaMail access work, the protocol must be POP3 or IMAP, because there´s no Notes provider. Changing every user mail system to Notes would be neraly impossible, so any ideas please? Thanks in advance. Re: Lotus Domino R5 Supports IMAP Author: ATUL MADNE (http://www.jguru.com/guru/viewbio.jsp?EID=1036993), Dec 12, 2002 Hi I'm trying to connect IMAP on Lotus Daomino R5 with javamail. But its giving error in authentication. Can u send me some sample code. Thanks in advance Atul Rmail with Lotus Author: Jaume Ba (http://www.jguru.com/guru/viewbio.jsp?EID=827369), Jul 9, 2002 There are some pleople using Rmail with notes in order to send mails. See: http://www.java4less.com/mail_e.htm Re:Problems while accessing Mails for IMAP Account from Lotus Domino
Server using JavaMail API. Author: Ananthalakshmi Subramaniyam (http://www.jguru.com/guru/viewbio.jsp?EID=768989), Dec 24, 2002 Hi, Does JavaMail is robust to Lotus Notes Mail Database? Since, we have developed a EMail Client application which works perfectly with MS-Exchange Server and when we have tested with Lotus Domino Server, we've faced the following problems: 1. Cannot able to get Mail Priority(High/Low) Flag 2. Sometimes, cannot able to get Mails from the InBox.NoContentException is thrown. 3. and sometimes, not able to view attachments,etc. Can anyone tell me the solution on this! Settings: 1. IMAP Account 2. IMAP task is running in Lotus Domino Server Thanks, Ananthalakshmi.H Re: Re:Problems while accessing Mails for IMAP Account from Lotus Domino Server using JavaMail API. Author: Thiadmer Sikkema (http://www.jguru.com/guru/viewbio.jsp?EID=1079811), Apr 28, 2003 NoContentException means probably that the content is Notes-RTF encoded instead of MIME. The Classes for Notes require pretty much custom coding to get the same result, but are far more flexible. How to get message id of the mail that is sent (not read)? Location: http://www.jguru.com/faq/view.jsp?EID=775190 Created: Feb 27, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by tolga evren (http://www.jguru.com/guru/viewbio.jsp?EID=530061 You'll need to subclass MimeMessage and get the id from the subclass after the header has been created. I believe you'll be able to get the generated header/id from updateHeaders(). Comments and alternative answers
Or just use MimeMessage itself Author: Peter Hewitt (http://www.jguru.com/guru/viewbio.jsp?EID=578744), Apr 13, 2002 I just used MimeMessage's getMessageID() to get the message id after sending the message and it worked for me. ... MimeMessage message = new MimeMessage(session); transport.sendMessage(message, message.getAllRecipients()); transport.close(); System.out.println("message id = " + message.getMessageID());
How can I access my Hotmail account through the JavaMail API? Location: http://www.jguru.com/faq/view.jsp?EID=787604 Created: Mar 7, 2002 Modified: 2002-04-11 11:14:30.661 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Hotmail doesn't use POP / IMAP. Instead, it uses a WebDAV based protocol (aka HTTPMail). There is a provider under development at SourceForge at http://sourceforge.net/projects/jhttpmail/. Comments and alternative answers
JDAVMail: a HotMail JavaMail service provider Author: Luc Claes (http://www.jguru.com/guru/viewbio.jsp?EID=103699), Apr 11, 2002 JDAVMail is a JavaMail service provider allowing JavaMail-compliant clients to access HotMail mailboxes (read/delete/move/copy mail, create/rename/delete folders, ...). The package was published under the LGPL licence and is available at http://jdavmail.sourceforge.net. Does the JavaMail API support embedded uuecoded blocks? Location: http://www.jguru.com/faq/view.jsp?EID=787899 Created: Mar 7, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Not directly, though there is nothing to stop you from extending the library to support it. What's new for JavaMail 1.3? Location: http://www.jguru.com/faq/view.jsp?EID=808326 Created: Mar 22, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The proposed changes for JavaMail 1.3 are listed at http://java.sun.com/products/javamail/JavaMail-1.3-changes.txt. Where can I find the sun.net.smtp.SmptClient class? Location: http://www.jguru.com/faq/view.jsp?EID=818683 Created: Mar 30, 2002 Modified: 2002-12-08 06:56:40.252 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) This class comes with the Sun runtime. As the package name of sun.net implies, it is non-standard and should not be used directly. How can I remove headers in JavaMail? Location: http://www.jguru.com/faq/view.jsp?EID=921226 Created: Jun 20, 2002 Author: Dieter Wimberger (http://www.jguru.com/guru/viewbio.jsp?EID=25708) Question originally posed by rajesh m (http://www.jguru.com/guru/viewbio.jsp?EID=473123
The MimeMessage has a method called removeHeader(String name) This will remove all headers with a given name. Note that the folder the message is in will have to be opened READ_WRITE at the point of modification. Probably you will want to make a copy and work on the copy MimeMessage(MimeMessage source) How can I convert an Outlook mailbox/data file to Linux mbox format? Location: http://www.jguru.com/faq/view.jsp?EID=935049 Created: Jul 2, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) There is a project over at Sourceforge that does exactly this for you. Never tried it myself, but you can grab it from http://sourceforge.net/projects/ol2mbox. How do I send a mail message at a certain time? Location: http://www.jguru.com/faq/view.jsp?EID=951553 Created: Jul 16, 2002 Modified: 2002-07-16 11:58:45.935 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Rahul gidwani (http://www.jguru.com/guru/viewbio.jsp?EID=950302 The java.util.Timer class permits timed execution of events. It is completely unrelated to what you want to do, like send mail. Comments and alternative answers
send mail Author: Andrew Sun (http://www.jguru.com/guru/viewbio.jsp?EID=877680), Jul 19, 2002 An easy way is to create your own runnable mail message object by extending java.mail.Message, add your own sendTime attribute. Then all you have to do is to start a timer, constantly checking for this sendTime value, Once System time pass this sendTime you can create a new thread and send this message off. Sending timed email Author: Mark Nuttall (http://www.jguru.com/guru/viewbio.jsp?EID=462679), Jul 23, 2002 Use a scheduler like Quartz. Re: How do I send a mail message at a certain time? Author: Daniel Szwalkiewicz (http://www.jguru.com/guru/viewbio.jsp?EID=804798), Jan 23, 2003 I have been using JCrontab for several months now for similar functionality and more. Everything from cleaning up log files, to uploading csv files to a database. I haven't had any issues with it and find it very reliable. If you think a unix-like cron system would help you out in your timed events, check out http://jcrontab.sourceforge.net
How to move message from one folder to another? Location: http://www.jguru.com/faq/view.jsp?EID=1010890 Created: Oct 10, 2002 Author: Asif Sajjad (http://www.jguru.com/guru/viewbio.jsp?EID=1010057) Question originally posed by chirag patel (http://www.jguru.com/guru/viewbio.jsp?EID=1006915 Here is the code I am using to move the messages to another folder. In findFolder method I search for the folder name and then open the folder to read-write. CurrentFolder is the folder from where the messages are copied to the destination folder. public void saveMessages(Message[] mArray, String folderName) throws Exception{ Folder f = findFolder(folderName); currentFolder.copyMessages(mArray, f); // Now the delete the messages from Current Folder for ( int i = 0; i < mArray.length; i++){ mArray[i].setFlag(Flags.Flag.DELETED, true); } currentFolder.expunge(); } [Keep in mind this is for IMAP only. POP doesn't support folders.] Comments and alternative answers
How do you get the new UID for the moved message? Author: Grace L (http://www.jguru.com/guru/viewbio.jsp?EID=1235917), May 9, 2005 Once the message is moved from one folder to another, the UID or message ID is changed. How do you get the new UID for that message? Thanks, Grace I want to use formating characters like tab (\t) in my mail messages but they are having no effect when the MIME type is text. How can I format my mail message? Location: http://www.jguru.com/faq/view.jsp?EID=1019675 Created: Oct 30, 2002 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by Jagadishwar Reddy Jannapureddy (http://www.jguru.com/guru/viewbio.jsp?EID=1019000 Tab characters in a text document can be interpreted differently by the program rendering the document, with different "tab stop" settings rendering them by different numbers of actual "blank space" characters (4 fixed spaces per tab, 8 fixed spaces, even possibly variable spacing, or even no spaces at all, as you are seeing, also depending on the fixed or variable font currently used in the rendering display program etc.). So if you are committed to plain text (yay for you!) I would perhaps insert a specific number of spaces, not a tab character.
If I am sending a signed mail to an end user, whose mailserver doesn't support S/MIME, what would happen to the message? Location: http://www.jguru.com/faq/view.jsp?EID=1022010 Created: Nov 5, 2002 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by shital mhatre (http://www.jguru.com/guru/viewbio.jsp?EID=965620 Servers traditionally aren't supposed to look inside the content of a message (well nowadays they do often filter for viruses). The S/MIME stuff only is in the headers and body of the message, not in the envelope. It's for use by the client MUA run by the recipient user, not by their server. So unless a filtering server thinks it's a virus or something, it should just get delivered to the recipient's mailbox, just like any other message. Why do I get a NullPointer exception when I create an InternetAddress? Location: http://www.jguru.com/faq/view.jsp?EID=1023591 Created: Nov 9, 2002 Author: Michael Dean (http://www.jguru.com/guru/viewbio.jsp?EID=805382) Question originally posed by Luiz Augusto Dzis (http://www.jguru.com/guru/viewbio.jsp?EID=945999 The InternetAddress(String) constructor method will throw a NullPointerException if the String reference passed to it is null. So, you might ask, why doesn't the documentation list that exception? Well, according to javadoc documentation standards, runtime exceptions (like NullPointerException) should never be listed in the "Throws" section of the javadoc. (Sun did this right. :) Instead, in a case like this--where the runtime exception could occur as a result of a bad parameter value---the documentation (method documentation or "Parameters" section) should specifically mention the possibility. (Sun forgot to do this.) How can you tell that you'll get a NullPointerException instead of an AddressException? Run this program: import javax.mail.MessagingException; import javax.mail.internet.InternetAddress; public class Test { public static void main(String[] args) { try { String test = null; InternetAddress address = new InternetAddress(test); System.out.println(address); } catch (MessagingException e) { System.err.println(e); e.printStackTrace(); } } }
Why do I keep getting a NULL when looking at the TO/FROM header fields? Location: http://www.jguru.com/faq/view.jsp?EID=1029946 Created: Nov 25, 2002 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by bannu naidu (http://www.jguru.com/guru/viewbio.jsp?EID=1026391 Messages are not required to have anything in any of the headers. In particular, it is OK to have no valid "From:" header (and OK to have no valid "To:" header also). Only the SMTP envelope fields are actually used, to transmit and deliver the message; the headers are not required. How could I include electronic signature and encryption in a JavaMail message? Location: http://www.jguru.com/faq/view.jsp?EID=1032292 Created: Nov 29, 2002 Author: Lasse Koskela (http://www.jguru.com/guru/viewbio.jsp?EID=573277) Question originally posed by Patrick Wong (http://www.jguru.com/guru/viewbio.jsp?EID=1018115 You can find an example of this at http://security.dstc.edu.au/projects/java/tutorials/messaging.html Comments and alternative answers
Link for this article does not appear to be working. Author: Christopher Lupton (http://www.jguru.com/guru/viewbio.jsp?EID=877975), Sep 11, 2003 This link does not seem to be in operation anymore. Is there another link or mirror to that article by any chance ? (Excellent FAQ by the way) Re: Link for this article does not appear to be working. Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7), Sep 11, 2003 Changing the original URL down to the java bit acts as a redirect to http://www.wedgetail.com/jcsi/. How do you send an SMS message using the JavaMail API? Location: http://www.jguru.com/faq/view.jsp?EID=1032299 Created: Nov 29, 2002 Author: Lasse Koskela (http://www.jguru.com/guru/viewbio.jsp?EID=573277) Question originally posed by mahadev hoolikeri (http://www.jguru.com/guru/viewbio.jsp?EID=1006902 First of all, you need an SMS gateway for sending SMS messages (unless you plan to code one yourself...) Take a look at, for example, www.kannel.org for an open source SMS gateway.
The way you actually send messages via a gateway is largely dependent on the gateway software's APIs. Some permit just using standard SMTP commands to send (and thus permit just using the regular JavaMail API). Comments and alternative answers
The Java solution would be to use SDK from www.simplwire.com Author: Shaji Kalidasan (http://www.jguru.com/guru/viewbio.jsp?EID=1015374), Dec 2, 2002 You can use the Java SDK from www.simplewire.com ( remember it is not a freeware but there is limited trial period and is very easy to implement ). There are lots of demo source code available. Alternatively you can try sending email ( now more GSM service providers accept SMTP email which can be send as SMS to mobile phones ) This is the SMS API I have worked. Consider other providers also. Thanks & regards, Shaji Kalidasan, [email protected] SMS from Java Author: Maxim Khukhro (http://www.jguru.com/guru/viewbio.jsp?EID=1076363), Apr 14, 2003 Hi! Take a look at SMLib tool - sending SMS via Java. http://www.unipro.ru/mobiles/smlib.html This can help you How do I send multiple messages using the same SMTP connection? When I use Transport.send(message), this always opens a new connection. Location: http://www.jguru.com/faq/view.jsp?EID=1035380 Created: Dec 8, 2002 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Gregory Ledenev (http://www.jguru.com/guru/viewbio.jsp?EID=1034651 The send method is static and doesn't care if you have connected or not. Use sendMessage. How do I deal with uuencoded attachments? Location: http://www.jguru.com/faq/view.jsp?EID=1041227 Created: Dec 26, 2002 Author: Christopher Koenigsberg
(http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by Rohan Desai (http://www.jguru.com/guru/viewbio.jsp?EID=1033718 First, uuencode/uudecode is not reliable (several characters vary in different implementations, and it is easy to damage, or incorrectly calculate/incompletely insert, the encoding). That's why MIME's base64 was invented. Second, uuencoded content is simply pasted in the main message body and is not a "multipart" message (has no MIME structure) and hence does not contain "attachments" (multiple body parts), from the MIME point of view. As far as actually doing the uuencode/decode operations... see the encode and decode methods of the MimeUtility class of the javax.mail.internet package. Comments and alternative answers
How to decode uuencoded attachments Author: Robert White (http://www.jguru.com/guru/viewbio.jsp?EID=1041462), Dec 27, 2002 Here's a utility class. class UUEncodedBodyPart { private InputStream _inStreamBodyPart = null; private String _sBodyPart = null; private String _sPossibleFileName = null; private int _headerIndex = -1, _endIndex = -1;
public UUEncodedBodyPart( String bodyPart ) throws Exception { this._sBodyPart = bodyPart; if ( ! findUUEncodedAttachmentPosition() ) { throw new Exception( "UUEncodedBodyPart.ctor():BodyPart does not seem to be uuEncoded" ); } else { ByteArrayInputStream bStream = new ByteArrayInputStream( bodyPart.substring( _headerIndex, _endIndex + 3 ).getBytes() ); try { _inStreamBodyPart = MimeUtility.decode( bStream, "uuencode" ); } catch ( MessagingException e ) { // This just to show what kind of exception can occur throw e; } } }
private boolean findUUEncodedAttachmentPosition() { int beginIndex = -1; String sSearch = _sBodyPart; if ( ( beginIndex = sSearch.lastIndexOf( BEGIN ) ) != -1 ) { int eolIndex = sSearch.indexOf( LINE_SEPARATOR, beginIndex ); String possibleHeader = sSearch.substring( beginIndex, eolIndex );
StringTokenizer st = new StringTokenizer( possibleHeader ); String possibleFileSize; st.nextToken();// this should be the begin try { possibleFileSize = st.nextToken(); int fileSize = Integer.parseInt( possibleFileSize ); _sPossibleFileName = st.nextToken(); // now we know we have a UUencode header. _headerIndex = beginIndex; _endIndex = sSearch.indexOf( END, beginIndex ); return true;
} catch ( NoSuchElementException nsee ) { // there are no more tokens in this tokenizer's string } catch ( NumberFormatException nfe ) { // possibleFileSize was non-numeric } } return false; } /** * Gets the fileName attribute of the UUEncodedBodyPart object * * @return The fileName value */ public String getFileName() { return ( _sPossibleFileName ); } /** * Gets the inputStream attribute of the UUEncodedBodyPart object * * @return The inputStream value */ public InputStream getInputStream() { return ( _inStreamBodyPart ); }
}
Now, to use the utility class... ... First, we have to recognize whether the JavaMail Part we are dealing with has String content (which means it may be UUencoded). If it is, we'll call a method to attempt to decode the attachment and save it as a file. If it cannot be decoded, it might just be a plain old text Part, such as the body of a text email. And, of course, if it's not String content that's a whole other ball o' wax. private Message classifyPart( Part part ) throws MessagingException, IOException { Object oContent = part.getContent(); if ( oContent instanceof String ) { String sPart = (String)oContent; // check for uuencoded files... if ( detachUUencodedFile( sPart ) ) { // file was written! } else { // error decoding Part or it's not uuencoded } } else if ( oContent instanceof Multipart ) { // snip... } else if ( oContent instanceof Message ) { // snip... } else { // unknown Part content } }
Here's the part that writes the attachment as a file.
private boolean detachUUencodedFile( String sPart ) throws IOException { try { // c'tor throws exception if string is not uuencoded, // or if there is a problem decoding the string. UUEncodedBodyPart bp = new UUEncodedBodyPart( sPart ); File file = new File( bp.getFileName() ); save( file, bp.getInputStream() ); return true; } catch ( IOException exIO ) { dbgOut( "detachUUencodedFile: " + exIO.getMessage() );
}
throw exIO; } catch ( Exception ex ) { dbgOut( "detachUUencodedFile: " + ex.getMessage() ); } return false;
static public long save( File file, InputStream is ) throws IOException { if ( ! file.createNewFile() ) { file.delete(); if ( file.exists() ) { throw new IOException( "file exists and cannot be deleted: '" + file.getAbsolutePath() + "'"); } } BufferedOutputStream bos = null; long lFileSize = 0; StringBuffer sb = new StringBuffer(); try { bos = new BufferedOutputStream( new FileOutputStream( file ) ); int iChar; while ( ( iChar = is.read() ) != -1 ) { sb.append((char)iChar); bos.write( iChar ); lFileSize++; System.out.println( sb.toString() ); } } catch ( IOException exIO ) { // explicitly close our output stream before deleting partial file if ( null != bos ) { bos.flush(); bos.close(); bos = null; } // don't leave behind any partial files if ( file.exists() ) file.delete(); // throw the exception again throw exIO;
} finally { // explicitly close our output stream if ( null != bos )
{
bos.flush(); bos.close();
} } return lFileSize; }
Re: How to decode uuencoded attachments Author: ratheesh nair (http://www.jguru.com/guru/viewbio.jsp?EID=1056362), Feb 12, 2003 Please tell me what is this BEGIN, END etc,., Re: How to decode uuencoded attachments Author: Dor Perl (http://www.jguru.com/guru/viewbio.jsp?EID=1060216), Feb 25, 2003 This is a nice code. However, it is dangerous to use it in a production server. The UUEncodedBodyPart constructor accepts a String and therefore an OutOfMemoryException might occur when the UUEncoded attachment is very big as this code requires keeping all of it in the memory. Maybe one attachment can not exceed an avarage amount of memory that a nowadays server has, but think about what might happen when several Threads in the same server handles some big UUEncoded attachments at the same time. BEGIN END LINE.. Author: beyler olivier (http://www.jguru.com/guru/viewbio.jsp?EID=1230141), Mar 1, 2005 What is the associated string to this constante ? Best regards How do I send email to a POP server? Location: http://www.jguru.com/faq/view.jsp?EID=1041233 Created: Dec 26, 2002 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) You don't send email to a POP server. You send email to an address which is handled by an SMTP server. Then there may be a POP server which clients can use, to read the mail, after it is accepted and delivered locally, by the associated SMTP server. How can I tell the JavaMail API where to create a mail folder on my IMAP server? Location: http://www.jguru.com/faq/view.jsp?EID=1041237 Created: Dec 26, 2002 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by Narayan Joshi (http://www.jguru.com/guru/viewbio.jsp?EID=965315
The JavaMail API, for an IMAP server, sends the IMAP command, to create a new folder, to the IMAP server. JavaMail does not create anything; the IMAP server creates the folder, when requested to by the JavaMail API's IMAP client commands. And then it's up to the IMAP server, where it wants to create this new folder, given its own configuration, in the underlying local filesystem, for folder locations relative to users' home directories (e.g. "/path/to/user1/path/to/folder1"). The IMAP server has to be able to FIND a folder, so it can't just create a folder anywhere; it has to create the folder in the place it knows to look for them, for a particular user. Either this is a single fixed location (e.g. "/home/user1/folder1") or it might have a folder search path taking multiple alternative possibilities, and this depends on the IMAP server. This has nothing to do with the JavaMail API. When does folder.getMessages() get the messages? Location: http://www.jguru.com/faq/view.jsp?EID=1041241 Created: Dec 26, 2002 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by chirag patel (http://www.jguru.com/guru/viewbio.jsp?EID=1006915 The JavaDoc for folder.getMessages says: ....Folder implementations are expected to provide light-weight Message objects, which get filled on demand. ..... And in the JavaDoc for Message it says: A Message object obtained from a folder is just a lightweight reference to the actual message. The Message is 'lazily' filled up (on demand) when each item is requested from the message. Note that certain folder implementations may return Message objects that are pre-filled with certain user-specified items. I'm getting my Session with Session.getDefaultInstance and its not getting changes to the Properties passed in. What's wrong? Location: http://www.jguru.com/faq/view.jsp?EID=1046816 Created: Jan 15, 2003 Modified: 2003-03-29 22:39:43.174 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) In getDefaultInstance(Properties props), the Properties are only used in the initial call. Future calls ignore the setting, returning the previously created Session. If you need to change the Properties, like to change SMTP servers, you should use getInstance(Properties props) instead. How are connection timeouts implemented? Location: http://www.jguru.com/faq/view.jsp?EID=1052347 Created: Jan 31, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) According to Bill Shannon, primary JavaMail engineer: The timeout is implemented by starting a thread to make the connection and if it doesn't complete before the
timeout, the thread is abandoned and left to die. (Unfortunately, there's no way to actually abort the connection attempt.) How can I log the debug messages to a file when I session.setDebug(true)? Location: http://www.jguru.com/faq/view.jsp?EID=1052582 Created: Jan 31, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) With the 1.3 release of JavaMail, there is support for session-level output streams. Call public void setDebugOut(java.io.PrintStream out) to change the stream from System.out. Passing in a value of null will use System.out for output. How do I send a message where a character with an accent is in the subject? Location: http://www.jguru.com/faq/view.jsp?EID=1052586 Created: Jan 31, 2003 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by Alfonso Garzon (http://www.jguru.com/guru/viewbio.jsp?EID=1045052 Email headers can only contain 7-bit US ASCII characters, according to the Internet standards (mainly RFC 2822, also 2821). For any characters outside that charset, they have to be encoded first. Your (sender's) email client should display the proper characters (accented etc.) to you when you are composing the message, but needs to encode them for transmission. The recipient's email client needs to decode them, for display at the other end. See RFC 2047 for details about encoding characters in email headers. Here are some classic examples, from RFC 2047, of some encoded text in email headers: From: =?ISO-8859-1?Q?Olle_J=E4rnefors?=
RFC 822 defines what a group address is. It allows one to prefix a list of email addresses with a label, followed by a colon, as in: jGurus: [email protected], John , "Joe"
Location: http://www.jguru.com/faq/view.jsp?EID=1063436 Created: Mar 5, 2003 Author: Jens Dibbern (http://www.jguru.com/guru/viewbio.jsp?EID=9896) Question originally posed by Shiv Kumar (http://www.jguru.com/guru/viewbio.jsp?EID=844764 You should configure a JavaMail resource for your EJB container and access it by JNDI. It works just like JavaMail in an application without setting up the connection first. You just get it from the JNDI tree. This should work for your MDB just like it workes for my stateless session bean Comments and alternative answers
JavaMail and Message Driven Bean Author: Ram V.L.T (http://www.jguru.com/guru/viewbio.jsp?EID=449849), Dec 17, 2004 Click Here for a good example of Working with the new Message Driven Beans and JMS Why do binary file attachment sizes increase by about 15-20% when sending a message? Location: http://www.jguru.com/faq/view.jsp?EID=1071376 Created: Mar 29, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) When included as an attachment, binary files are encoded to be 7-bit safe. This means that what used to be 8-bits per byte is now 7, hence the increase. Can I create a MimeMessage using one Session say session1 and send the mail using another Session session2? Location: http://www.jguru.com/faq/view.jsp?EID=1071379 Created: Mar 29, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by manjunath somashekar (http://www.jguru.com/guru/viewbio.jsp?EID=1063490 Sure. import java.util.Properties; import javax.mail.*; import javax.mail.internet.*; public class MailExample { public static void main (String args[]) throws Exception { String host = args[0]; String from = args[1]; String to = args[2]; String username = args[3]; String password = args[4]; // Get system properties Properties props = System.getProperties();
// Setup mail server props.put("mail.smtp.host", host); // Get session Session session = Session.getInstance(props, null); // Define message MimeMessage message = new MimeMessage(session); message.setFrom(new InternetAddress(from)); message.addRecipient(Message.RecipientType.TO, new InternetAddress(to)); message.setSubject("Hello JavaMail"); message.setText("Welcome to JavaMail"); Session session2 = Session.getInstance(props, null);
}
// Send message Transport transport = session2.getTransport("smtp"); transport.connect(host, username, password); transport.sendMessage(message, message.getAllRecipients()); transport.close();
} How do I display POP3 message body properly in a browser? When i use message.writeTO() it displays without line breaks. Location: http://www.jguru.com/faq/view.jsp?EID=1071381 Created: Mar 29, 2003 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by srinivas Rao (http://www.jguru.com/guru/viewbio.jsp?EID=1062741 Of course an HTML browser is rendering HTML, meaning that it is ignoring whitespace, including newlines. You could try enclosing your text in a "<pre>" element. Or you could insert the HTML for linebreaks yourself ("
" or else enclose in "
How do I display POP3 message body properly in a browser? When i use message.writeTO() it displays without line breaks. Author: Md Razzak Sorker (http://www.jguru.com/guru/viewbio.jsp?EID=1115939), Sep 17, 2003 First you have to check the message mimeType is text/html or not if so then you have to read the inputsteam then make a bufferedreader and read the content line by line and print it, the code should look somthing like this: <% if (msg.isMimeType("text/html")) { BufferedReader reader = new BufferedReader(new InputStreamReader(msg.getInputStream())); while((msgText=reader.readLine())!=null) { %> <%= msgText %> <% } } %>
Formatting a brwser friendly message Author: James Fuhr (http://www.jguru.com/guru/viewbio.jsp?EID=1140414), Jan 21, 2004 The standard linebreak in an email appears as \r\n. If you are using an IDE such as NetBeans, set a Watch on the variable storing the line and run in debug. You should see those escape characters. What I ended up doing, was manually insert the line break HTML tag while reading each line of the message. The sample code below checks the content type of the message. If it is text/plain, it creates the
tags InputStream is = messagePart.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String thisLine=reader.readLine(); StringBuffer msg = new StringBuffer(); while (thisLine!=null) { msg.append(thisLine); //check the content type; append if plain text if(mailMessage.contentType.startsWith("text/plain")) { msg.append("
"); } thisLine=reader.readLine();
}
Can someone please specify the technique of message sorting within folder according to some criteria say Header Information? Location: http://www.jguru.com/faq/view.jsp?EID=1071382 Created: Mar 29, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Wolverine X (http://www.jguru.com/guru/viewbio.jsp?EID=1060213 Since the Message class doesn't implement the Comparable interface, you'll need to create a custom Comparator. Then, you can call Arrays.sort(arrayOfMessages, comparator). Is it possible to send a message that identifies if the mailreader is configurate to read HTML or text mail? Location: http://www.jguru.com/faq/view.jsp?EID=1072695 Created: Apr 2, 2003 Modified: 2003-04-03 04:48:51.163 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by marcelo serra (http://www.jguru.com/guru/viewbio.jsp?EID=1071681 The MIME content-type "multipart/alternative" is intended so you can send different versions of the same "message" all bundled together, e.g. an HTML version, a plain
text version, maybe an audio version, etc., and let the remote mail reading client decide for itself, which one is appropriate for it, and for its current user. Comments and alternative answers
On the multipart/alternative... Author: Gabi Lacatus (http://www.jguru.com/guru/viewbio.jsp?EID=1071969), Aug 19, 2003 I noticed that the order of the parts count too. If I put the text/plain first and then a text/html then pine for example opens the text/plain part and Outlook opens the html part(But it also shows the text/plain part as an attachment while other mail clients do not - WHY?) If the text/html part is inserted first then even pine opens the html code :((...how come?Could it be a server configuration matter? Re: On the multipart/alternative... Author: Neil Boemio (http://www.jguru.com/guru/viewbio.jsp?EID=1128781), Nov 17, 2003 Did you ever figure out the issue with Outlook showing both the HTML part and the Text part of the multipart/alternative e-mail? Example Code Author: Kevin Bridges (http://www.jguru.com/guru/viewbio.jsp?EID=1119238), Oct 2, 2003 // Create the message to send Properties props = new Properties(); props.put("mail.smtp.host", "localhost"); Session session = Session.getInstance(props,null); MimeMessage message = new MimeMessage(session);
// Create the email addresses involved InternetAddress from = new InternetAddress("[email protected]"); InternetAddress to = new InternetAddress("[email protected]"); // Fill in header message.setSubject("I am a multipart text/html email" ); message.setFrom(from); message.addRecipient(Message.RecipientType.TO, to); // Create a multi-part to combine the parts Multipart multipart = new MimeMultipart(); // Create your text message part BodyPart messageBodyPart = new MimeBodyPart(); messageBodyPart.setText("Here is your plain text message"); // Add the text part to the multipart multipart.addBodyPart(messageBodyPart);
// Create the html part messageBodyPart = new MimeBodyPart(); String htmlText = "I am the html part
"; messageBodyPart.setContent(htmlText, "text/html"); // Add html part to multi part multipart.addBodyPart(messageBodyPart); // Associate multi-part with message message.setContent(multipart); // Send message Transport.send(message);
Re: Example Code Author: sarah sarah (http://www.jguru.com/guru/viewbio.jsp?EID=1250544), Jun 27, 2005 This will work - both the html and plain text will be sent, but only the one favoured by the recipient program will be displayed. BUT, you forgot to make it multipart/alternative! the way it is, both types will be displayed. To make this work as intended, it must be Multipart multipart = new MimeMultipart("alternative"); Also, just thought I'd mention that apparently the order is important. Add the plain text before the html version, since AOL users always get both and the html doesn't display right (so they'd have to scroll all the way to the bottom). I haven't tested this out myself though. Re[2]: Example Code Author: Java Buddha (http://www.jguru.com/guru/viewbio.jsp?EID=1251857), Jul 5, 2005 Hi Sarah, If I add HTML version before Text version it works fine in most of the clients Pine, Micorsoft outlook, gmail etc., I didn't check it in AOL as I don't have an account. But then as you said, I tried adding the HTML version after Text version and checked the mail sent with Pine software. Pine now displays the HTML and Text both, previously it was displaying only Text version. Kindly help me out of this. Thanks, Shenbag What is the format of the Content-ID header? Location: http://www.jguru.com/faq/view.jsp?EID=1075898 Created: Apr 12, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The Content-ID header, set with setContentID, needs to be formatted like
Created: Apr 25, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) JavaMail 1.3.1 includes over 20 bug fixes, as well as support for DIGEST-MD5 authentication in the SMTP provider (courtesy of Dean Gibson). How do I configure JavaMail to work through my proxy server? Location: http://www.jguru.com/faq/view.jsp?EID=1080812 Created: Apr 30, 2003 Author: Christopher Koenigsberg (http://www.jguru.com/guru/viewbio.jsp?EID=722897) Question originally posed by SKD SKD (http://www.jguru.com/guru/viewbio.jsp?EID=1077304 Proxy servers redirect HTTP connections, not JavaMail connections. In order to connect from behind a firewall for POP3, IMAP, and SMTP access, you need to connect to a SOCKS server. Your sys admin should provide you with SOCKS client software, to install on your client machine. (Hummingbird, for instance, for Windows; various clients for Solaris; I think Linux, at least RedHat, already comes with a SOCKS client?) The SOCKS versions have to match, on the client and SOCKS server. It's transparent to network applications, e.g. they just think they are making normal connections, but the TCP stack internally tunnels these through SOCKS instead. So the only thing to configure is the SOCKS client software on the host. How do I get the size of a message that I am going to send? The getSize() method works fine with received message but returns -1 if I use it with a message that I am going to send! Location: http://www.jguru.com/faq/view.jsp?EID=1080814 Created: Apr 30, 2003 Author: fernando fernandes (http://www.jguru.com/guru/viewbio.jsp?EID=400255) Question originally posed by fernando fernandes (http://www.jguru.com/guru/viewbio.jsp?EID=400255 Get the InputStream for the message with getInputStream() and count the bytes. Where can I find a regular expression to validate an email address? Location: http://www.jguru.com/faq/view.jsp?EID=1088553 Created: May 27, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) One is available at http://www.ex-parrot.com/~pdw/Mail-RFC822-Address.html. Comments and alternative answers
Here is the regular Expression for Email validation Author: praveen J (http://www.jguru.com/guru/viewbio.jsp?EID=1140476), Jan 21, 2004 public static boolean isValidEmailAddress(String email) { String regex = "^[_A-Zaz0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*(\\.[_A-Za-z0-9-]+)" ; return email.matches(regex) ; }
How do I find out if an IMAP server supports a particular capability? Location: http://www.jguru.com/faq/view.jsp?EID=1093517 Created: Jun 12, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) If you have a folder open, you can do this: import com.sun.mail.imap.IMAPFolder; import com.sun.mail.imap.protocol.IMAPProtocol; IMAPProtocol p = ((IMAPFolder)folder).getProtocol(); if (p.hasCapability("FOO")) ... See the com.sun.mail.imap package javadocs for additional details and important disclaimers. How do I get rid of unused connections? Doing something like checking for the existance of an IMAP folder leaves the connection open. Location: http://www.jguru.com/faq/view.jsp?EID=1110073 Created: Aug 21, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by George Lindholm (http://www.jguru.com/guru/viewbio.jsp?EID=1065564 You can set the connection pool timeout property (mail.imap.connectionpooltimeout for imap). Then... according to JavaMail architect Bill Shannon: Because JavaMail doesn't use a separate thread to manage the timeout, it only checks for connections to timeout when you do something with the Store. Adding a call to store.isConnected() after the timeout should trigger the timeout/disconnect. How do I package a JavaMail application into a single jar file along with the mail.jar and activation.jar? Location: http://www.jguru.com/faq/view.jsp?EID=1111058 Created: Aug 26, 2003 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Question originally posed by Glenn Wiens (http://www.jguru.com/guru/viewbio.jsp?EID=458756 You need to unjar all the JAR files into a single directory tree and then JAR them back up. The trick is preserving the location of some files:
425 Fri Dec 01 00:05:16 EST 2000 INF/javamail.default.providers 12 Fri Dec 01 00:05:16 EST 2000 INF/javamail.default.address.map 1124 Fri Dec 01 00:05:16 EST 2000 INF/javamail.charset.map 469 Fri Dec 01 00:05:16 EST 2000
METAMETAMETAMETA-INF/mailcap
Make sure these end up in the same location in the new JAR.
How do I calculate the size of an entire folder? Location: http://www.jguru.com/faq/view.jsp?EID=1137806 Created: Jan 8, 2004 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) For POP3, you can get this information for the INBOx with <size=2>com.sun.mail.pop3.POP3Folder.getSize(). For IMAP, the protocol doesn't support this feature. You would need to sum the sizes of the contained messages. How do I get the sender of an email? Location: http://www.jguru.com/faq/view.jsp?EID=1251270 Created: Jun 30, 2005 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The getFrom() of Message is one way, but the getSender() method of MimeMessage reads the RFC 822 Sender header field. A value of null is returned if the header isn't present. Comparing the two allows you to see if someone is lying. :-) How do I set the default character encoding for JavaMail to use? Location: http://www.jguru.com/faq/view.jsp?EID=1251271 Created: Jun 30, 2005 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The mail.mime.charset system property is used. If unset, used instead.
file.encoding is
How do I find out the number of deleted messages in a folder? Location: http://www.jguru.com/faq/view.jsp?EID=1251272 Created: Jun 30, 2005 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) Added with JavaMail 1.3, the getDeletedMessageCount() method of Folder gets this for you. A -1 may be returned if the server doesn't support the operation. How is JavaMail licensed? Location: http://www.jguru.com/faq/view.jsp?EID=1255606 Created: Jul 29, 2005 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) As of July 2005, JavaMail is licensed with GlassFish under Sun's CDDL open source license. What version of JavaMail does GlassFish contain? Location: http://www.jguru.com/faq/view.jsp?EID=1255607 Created: Jul 29, 2005 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) According to Bill Shannon of Sun, the July 2005 release of GlassFish contains JAF 1.1ea and a version of JavaMail slightly newer than 1.3.3ea.
What is GlassFish? Location: http://www.jguru.com/faq/view.jsp?EID=1255621 Created: Jul 29, 2005 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) The GlassFish Project is Sun's open source application server project. Found at https://glassfish.dev.java.net/, you can participate in the development of the latest version of Sun's Java System Application Server PE 9.0. It is based on Java Enterprise Edition 5. What string do I pass to SimpleDateFormat to format the message date to spec - getSentDate() method of Message? Location: http://www.jguru.com/faq/view.jsp?EID=1259133 Created: Aug 22, 2005 Author: John Zukowski (http://www.jguru.com/guru/viewbio.jsp?EID=7) There is no need to create a custom DateFormat. The MailDateFormat class found in the javax.mail.internet handles all this for you. It formats and parses the date based on the draft-ietf-drums-msg-fmt-08 dated January 26, 2000. This is a followup spec to RFC-822.