日期:2014-05-17 浏览次数:20766 次
mimeMsg.setContent(mp);
mimeMsg.saveChanges();
// System.out.println("正在发送邮件....");
Session mailSession = Session.getInstance(props, null);
Transport transport = mailSession.getTransport("smtp");
try {
if (smtpport != null && !smtpport.equals("") && !smtpport.equals("25") ) {
transport.connect((String) props.get("mail.smtp.host"),Integer.valueOf(smtpport), username, password);
}else{
transport.connect((String) props.get("mail.smtp.host"),username, password);
}
//System.out.println("连接成功!");
} catch (MessagingException e) {
SendEmailOperate.wrongMessage.put("faleReason", "连接邮件服务器时发生错误");
e.printStackTrace();
//System.out.println("SMTP无效!");
}
try {
System.out.println(mimeMsg.getAllRecipients()[0].toString());
transport.sendMessage(mimeMsg,mimeMsg.getAllRecipients());
} catch (Exception e) {
SendEmailOperate.wrongMessage.put("faleReason", "邮件发送时发生错误");
//e.printStackTrace();
}
//Transport.send(mimeMsg);
// System.out.println("发送邮件成功!");
transport.close();
//一直执行没有报异常,但进入收件箱就是没有信息,
return true;