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("[email protected]"));
		Transport transport = session.getTransport();
		transport.connect("smtp.163.com", 25, "usedto321", "123456");
		transport.sendMessage(msg,new Address[]{new InternetAddress("[email protected]")});
		transport.close();
	}
}

 

你可能感兴趣的:(java)