String sendTo = "
//设置抄送人
String sendCC = "
//设置发件人
String sendFrom = "
try{
//获得发送实体
SMTPTransport t = (SMTPTransport)session.getTransport(ssl ? "smtps" : "smtp"); 软件测试
//与SMTP主机相连
t.connect("
MimeMessage msg = new MimeMessage(session);
//设置邮件各个字段
String subject = "
String personalName = "
String body = "
String charset = "utf-8";
InternetAddress[] to = new InternetAddress[1];
InternetAddress from = new
InternetAddress(sendFrom,personalName,charset);
to[0] =new InternetAddress(sendTo,personalName,charset);
msg.setFrom(from);
msg.setRecipients(Message.RecipientType.TO,to);
msg.setSubject(subject,charset);
msg.setText(body,charset);
msg.setSentDate(new Date());
//发送邮件
t.sendMessage(msg, msg.getAllRecipients());
}
catch (Exception e){
e.printStackTrace();
}
return 0;
}//end of action
文章来源于领测软件测试网 https://www.ltesting.net/