DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Sun Microsystems, Inc]
DEBUG SMTP: useEhlo true, useAuth true
DEBUG SMTP: trying to connect to host "smtp.126.com", port 25, isSSL false
DEBUG SMTP: exception reading response: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?
org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Exception reading response;
代码如下
JavaMailSenderImpl mailSend=new JavaMailSenderImpl();
mailSend.setDefaultEncoding("UTF-8");//编码
mailSend.setHost(getWebServicePz("shxt.mail.host"));//mail端口协议
mailSend.setPassword(getWebServicePz("shxt.mail.password"));//密码
mailSend.setUsername(getWebServicePz("shxt.mail.username"));//用户名@前面
Properties properties = new Properties();
properties.setProperty("mail.debug", "true");//是否显示调试信息(可选测试用)
properties.setProperty("mail.transport.protocol", "smtp");//协议
properties.setProperty("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
properties.setProperty("mail.smtp.auth", "true");//设置用户验证
properties.setProperty("mail.smtp.timeout","250000");//超时时间
mailSend.setJavaMailProperties(properties);
MimeMessage msg = mailSend.createMimeMessage();
MimeMessageHelper message = new MimeMessageHelper(msg, false, "UTF-8");
message.setFrom(getWebServicePz("shxt.mail.from"));
message.setSubject("上会通知"); //主题
message.setTo(toEmails); //发件人
String htmlTemplate=mailTzTemplate(hyxx,template,hys,yhryLst,ytList);//freemark网页模板
message.setText(htmlTemplate, true); // 如果发的不是html内容去掉true参数
mailSend.send(msg);