Java郵件發送解決ssl及郵件中文亂碼
org.apache.commons.mail.EmailException: Sending the email to the following server failed : smtp.qiye.163.com:25
Caused by: javax.mail.AuthenticationFailedException: 535 5.7.0 ERR.LOGIN.NONSSL
導入jar包
compile('org.apache.commons:commons-email:1.3.3')
/** * 發送郵件給指定的人 * * @param toEmial 郵件 * @param subject 主題 * @param content 內容 * @return * @throws Exception */ public String sendEmail(String[] toEmial, String subject, String content) { try { HtmlEmail simpleEmail = new HtmlEmail(); simpleEmail.setHostName(getHostName()); simpleEmail.setAuthentication(this.getFromAddr(), this.getMailPassword()); simpleEmail.setFrom(getFromAddr(), getFromName()); simpleEmail.addTo(toEmial); simpleEmail.setSubject(subject); simpleEmail.setMsg(content); //add simpleEmail.setSSLOnConnect(true); simpleEmail.setCharset(StandardCharsets.UTF_8.name()); return simpleEmail.send(); } catch (Exception e) { logger.error("發送郵件異常:", e); } return null; }
ssl郵箱默認端口號:465