javamail邮件开发入门(2)
简单的接收邮件的例子:
public static void main(String[] args) { Properties props = new Properties(); props.put("mail.store.protocol", "pop3"); props.put("mail.pop3.auth ", "true"); Session session = Session.getInstance(props, null); session.setDebug(true); try { Store store = session.getStore(); store.connect("pop.qq.com", "654166020@qq.com", "xx520gaoyong"); Folder folder = store.getFolder("inbox"); folder.open(Folder.READ_ONLY); Message message = null; if (folder.getMessages().length > 0) { message = folder.getMessages()[0]; } System.out.println("*******内容如下*******"); System.out.println(message.getSubject()); System.out.println("*************************"); folder.close(true); store.close(); } catch (MessagingException mex) { System.out.println("send failed, exception: " + mex.getMessage()); } }
?