发邮件暂存

package test;

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 sendMail {

	public static void main(String[] args) throws MessagingException {
		//创建session对象
		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对象
		Message msg = new MimeMessage(session);
		msg.setText("ok");
		msg.setFrom(new InternetAddress("[email protected]"));
		Transport transport = session.getTransport();
		transport.connect("smtp.qq.com",25, "[email protected]", "xyyareuiigbecada");
		transport.sendMessage(msg,new Address[]{new InternetAddress("[email protected]")});
		transport.close();
	}

}

 

你可能感兴趣的:(Java学习之路)