Transport t=session.getTransport();

package com.itheima.tfy.mail;


import java.util.Properties;


import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;


public class SendMail {


/**
* @param args
* @throws MessagingException 
* @throws Exception 
*/
public static void main(String[] args) throws Exception, MessagingException {
Properties props=new Properties();

props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.163.com");
props.setProperty("mail.smtp.auth", "true");//请求身份认证


Session session=Session.getInstance(props);

session.setDebug(true);
MimeMessage mm=new MimeMessage(session);
mm.setFrom(new InternetAddress("[email protected]"));//设置发件人
mm.setRecipients(Message.RecipientType.TO, "[email protected]");//设置收件人
mm.setSubject("tfy hello world!!!");//
mm.setText("lsdsindsdlggin 哎哟不错哦");//设置


mm.saveChanges();

//发出邮件
Transport t=session.getTransport();
t.connect("itheimacloud", "iamsorry");
t.sendMessage(mm,mm.getAllRecipients());
t.close();
}


}

你可能感兴趣的:(Transport t=session.getTransport();)