星期三 四月 05, 2006
jungleford如是说
近来在完善一个简单的邮件客户端程序,还好SUN J2EE SDK提供了JavaMail API,我们可以方便地调用它已经封装好的接口而不用理会协议本身的实现。但现在很多mail服务器都提供的是POP协议接收邮件,由于POP3是“无状态”的协议,服务器端不保存诸如标记这样的任何状态,你把一封邮件移到“垃圾箱”里在服务器端看来和其它邮件并没有什么区别,所以所有邮件状态的解析工作全部留给客户端处理,这就是为什么利用JavaMail编写接收邮件的程序要比编写发送邮件的程序要困难不少的原因。尽管JavaMail封装得相当不错,但写一个好的邮件客户端仍需要对基本协议有一定的了解,初次接触JavaMail的朋友可能会有一些困惑,譬如:为什么Message对象不是可序列化的对象,否则我的客户端解析起来可能方便得多;为什么对中文内容的邮件支持得不好,我应当如何实现自己的中文邮件处理方案;……下面转载一篇在SUN官方网站上提供的JavaMail API FAQ,它会对你的疑问有一个初步的解释,后面还有它的中文译文,转自SUN中国网站。不过清晰的概念还是了解协议和RFC比较好,比如RFC 822等。
JAVAMAIL API
General
- What is the JavaMail API?
- How do I get an implementation of the JavaMail API?
- How do I send feedback or comments?
- Where is
javax.activation? - What JDK does JavaMail API need?
- Where can I find a version of JavaMail for my favorite operating system?
- Do the JavaMail APIs work in web browsers?
- Can I use JavaMail to read mail from my web mail account (such as Yahoo or Hotmail)?
- What is IMAP?
- What is SMTP?
- What is MIME?
- What is POP3?
- What about support for MAPI, NNTP, Lotus Notes, and other service providers?
- How do I store mail messages on my local disk?
- Where do I find documentation on the Sun protocol providers?
- Is the JavaMail API implementation completely free? Can I ship it along with my product?
- Can I get the source code for the JavaMail API implementation?
- Is JavaMail Y2K compliant?
- The answer to my question isn't here, where else should I look?
Installation and Configuration
- How do I install the JavaMail API implementation?
- Does JavaMail include all the necessary mail servers?
- Where can I get the necessary mail servers?
- What host name, user name, or password should I use?
- How do I configure JavaMail to work through my proxy server?
- How do I set my CLASSPATH on Windows NT?
- While trying to run my program on Linux I get a very strange error message and the program fails. What did I do wrong?
- How do I use JavaMail in an application run under a SecurityManager; what permissions must I grant to the application and to JavaMail?
- How do I configure my web server to run the JavaMail demo servlet?
- When using JavaMail in my servlet, it is unable to find any of the JavaMail classes. I've added mail.jar to the server's CLASSPATH.
- My servlet can find the JavaMail classes, but JavaMail complains that it can't find a service provider for "smtp" or "imap" or address type "rfc822".
- Where can I find jws.jar? I've installed Java Web Server 2.0 and am trying to run the JavaMailServlet. The README file instructs me to add jws.jar to my CLASSPATH.
Programming
- Where can I learn the basics about Internet email that I'll need to know to program JavaMail effectively?
- How do I debug my application that uses JavaMail APIs?
- How do I send a message with an attachment?
- How do I read a message with an attachment and save the attachment?
- How do I tell if a message has attachments?
- How do I create a multipart message with a part of any MIME type I choose?
- What is "disconnected support"?
- How do I support disconnected operation using the JavaMail APIs?
- How do I send secure email using the JavaMail APIs?
- The
writeTo()method generates message text with lines that are neither the canonical MIME representation of the data (i.e., using CRLF to terminate lines), nor using the canonical line separator of my platform (e.g., "n" on UNIX). How do I get either of these representations if I need them? - Can I use the JavaMail APIs to implement a mail server?
- Can I use the JavaMail APIs to add new user accounts to my mail server, remove user accounts from my mail server, or change the passwords for user accounts on my mail server?
- Why doesn't the MimeMessage class implement Serializable so that I can serialize a message to disk and read it back later?
- How do I write a Service Provider?
- I'm having trouble logging into my Microsoft Exchange server, even though I'm sure I'm using the correct username and password, what could I be doing wrong?
- How do I encode a binary file before sending it and how do I decode it when I receive it?
- If I don't need to encode and decode attachments myself, when should I use the
MimeUtilitymethods? - Even though JavaMail does all the encoding and decoding for me, I need to manually control the encoding for some body parts.
- Why doesn't JavaMail properly encode and decode filenames in non-ASCII character sets?
Reading mail, IMAP
- I tried running your demos against my IMAP server, but I get an error.
- The IMAP provider seems to lose data when I fetch messages with large attachments.
- Does the IMAP provider cache the retrieved data?
- I want to move messages between folders. Should I use
appendMessages()orcopyMessages()? - Retrieving large message bodies seems inefficient at times.
- I get OutOfMemory errors when loading this large binary attachement.
- Why do I get the UnsupportedDataTypeException when I invoke
getContent()on a bodypart? - Why do I get the UnsupportedEncodingException when I invoke
getContent()on a bodypart that contains text data?
Sending mail, SMTP
- How do I reply to a message?
- How do I forward a message?
- How do I send HTML mail?
- How do I send mail with formatted text using different fonts and colors?
- How do I send mail with both plain text as well as HTML text so that each mail reader can choose the format appropriate for it?
- How do I send mail HTML mail that includes images?
- What's the difference between the Transport methods
sendandsendMessage? - I need to authenticate to my SMTP server so I call
trans.connect(host, user, password)and thentrans.send(msg)to send the message, but it's not working. - I modified this message, but the headers do not reflect the changes.
- I'm using the
sendMessage()method to send my message but the message comes out with strange looking lines before and after my text, and my attachments appear in the body of my message. - I set a particular value for the Message-ID header of my new message. But when I send this message, that header is rewritten.
- Why do I get an UnsupportedDataTypeException when sending this new message that I created?
- How can I explicitly set the SMTP FROM: attribute when sending a message?
- I want to repeatedly send messages, to a different set of recipients each time. But invoking
Transport.send(Message)causes a new Transport session to be established each time. This is suboptimal in this case, so how do I get around this? - I get "MessagingException: 501 HELO requires domain address" when trying to send a message.
- If I send a message to a bad address, why don't I get a SendFailedException or TransportEvent indicating that the address is bad?
- When a message can't be delivered, a failure message is returned. How can I detect these "bounced" messages?
- When I construct an InternetAddress object, why don't I get an exception if the address is illegal?
- When I try to send a message, why do I get
javax.mail.SendFailedException: 550 Unable to relay for my-address? - When I try to send a message to (for example) Yahoo, why do I get an error that says "connection refused"?
- When sending mail why does it fail with an exception that includes a message something like "553 To send mail, first check your mail with a valid POP account"?
POP3
- Where do I find support for POP3?
- I want to delete messages on a POP3 server. I set the
DELETEDflag on those messages. Then I call theexpunge()method, but I get a MethodNotSupportedException. How do I delete messages when I use Sun's POP3 provider? - How can I retrieve POP3 UIDLs in messages obtained from Sun's POP3 provider?
- How can I tell which messages are new with POP3?
- Why does
hasNewMessages()always return false when using POP3? - I set up a
MessageCountListener(as demonstrated in themonitorprogram) but I'm never notified of new mail in my POP3 INBOX. - Why does
getReceivedDate()return null when using POP3? - When using POP3 I get complaints about the SocketFetcher class.
- When using POP3 I get complaints about the contentStream field.
- How do I access or create folders other than INBOX on my POP3 server?
- Why does the
getSizemethod return a negative number when using POP3?
JavaMail in servlets
JavaMail in applets
- Can I use JavaMail in applets?
- What are the security implications of using JavaMail in an applet?
- Ok, maybe I really don't want to use an applet, what should I do instead?
Comments:
Search This Site
Recent Entries
- 【转贴】类 DateFormatSymbols
- 暂时先贴到这里了
- SmartCalendar 0.1 beta released!
- SmartCalendar新增JNLP发布!
- MSNHC居然被人继续开发下去了
- 【转贴】-jar参数运行应用时classpath的设置方法
- 5.0之new feature初体验(2005年10月)
- 【翻译】log4j的PatternLayout参数含义(2005年10月)
- MSNHistoryCombiner的一点心得
- 从Jar包获取资源的方法(2005年6月)
- 【翻译】仿射变换(2005年11月)
- MSN历史记录合并工具MSNHistoryCombiner新鲜出炉(2005年6月)
- “给你第二次机会”——小议PushbackInputStream(2005年3月)
- 存取程序状态的几种方法——Java I/O应用杂谈(2005年3月)
- Java调试的变迁:从System.out.println到log4j(2004年12月)
- 关于集合框架的思考(2004年12月)
- 我的JavaMail客户端 - JExp(2004年11月)
- JavaMail API FAQ 译文
- JavaMail API FAQ
- 利用Observer模式解决组件间通信问题(2004年9月)