首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > 编程 >

Java邮件范例01

2012-10-27 
Java邮件实例01package demoimport java.util.Propertiesimport javax.mail.Addressimport javax.mail.

Java邮件实例01

package demo;import java.util.Properties;import javax.mail.Address;import javax.mail.Message;import javax.mail.MessagingException;import javax.mail.Session;import javax.mail.Transport;import javax.mail.internet.InternetAddress;import javax.mail.internet.MimeMessage;public class Dome1 {public static void main(String[] args) throws MessagingException {Properties props = new Properties();props.setProperty("mail.smtp.auth", "true");props.setProperty("mail.transport.protocol", "smtp");Session session = Session.getInstance(props);session.setDebug(true);Message msg = new MimeMessage(session);msg.setText("你好!");msg.setFrom(new InternetAddress("usedto321@163.com"));Transport transport = session.getTransport();transport.connect("smtp.163.com", 25, "usedto321", "123456");transport.sendMessage(msg,new Address[]{new InternetAddress("usedto321@163.com")});transport.close();}}

?

at demo.T.main(T.java:20)

热点排行