/*** 发送邮件
*@paramuser 发件人邮箱
*@parampassword 授权码(注意不是邮箱登录密码)
*@paramhost
*@paramfrom 发件人
*@paramto 接收者邮箱
*@paramsubject 邮件主题
*@paramcontent 邮件内容(可以是字符串也可以是HTML格式)
*@returnsuccess 发送成功 failure 发送失败
*@throwsException*/
public staticString sendMail(String user, String password, String host,
String from, String to, String subject, String content) {if (to != null){try{
Properties props=System.getProperties();
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");
MailAuthenticator auth= newMailAuthenticator();
MailAuthenticator.USERNAME=user;
MailAuthenticator.PASSWORD=password;
Session session=Session.getInstance(props, auth);
session.setDebug(true);
MimeMessage message= newMimeMessage(session);
message.setFrom(newInternetAddress(from));if (!to.trim().equals("")){
message.addRecipient(Message.RecipientType.TO,newInternetAddress(to.trim()));
}
message.setSubject(subject);
MimeBodyPart mbp1= new MimeBodyPart(); //正文
mbp1.setContent(content, "text/html;charset=utf-8");
Multipart mp= new MimeMultipart(); //整个邮件:正文+附件
mp.addBodyPart(mbp1);//mp.addBodyPart(mbp2);
message.setContent(mp);
message.setSentDate(newDate());
message.saveChanges();
Transport.send(message);
}catch(Exception e){
e.printStackTrace();return "failure";
}return "success";
}else{return "failure";
}