Using the JavaMail API provided by Sun, you can easily develop mail-sending programs. You may already be able to use it to send a simple text, but do you want to make your program send attachments like Outlook? After a brief introduction of JavaMail, this article explains in detail a complete messenger JavaBean and a very lightweight servlet.
(Readers without loading the JavaMail API can download to this site and set up classpath according to Readme.txt)
A, javamail some of the classes we need
1.Properties
JavaMail requires properties to create a Session object whose property value is the host that sends the message, such as:
Properties props = new Properties ();
props.put("mail.smtp.host", "smtp.xxxx.com");//可以换上你的smtp主机名,就像你在OutLook中设置smtp主机名一样。
2.Session
All JavaMail programs require at least one or all of the conversation goals.
Session session = Session.getInstance(props, null);
3.MimeMessage
The information object will truly reflect the message you send.
MimeMessage msg = new MimeMessage(session);
4.Transport
The sending of a message is done by transport:
Transport.send(msg);