Java邮件发送解决ssl及邮件中文乱码

Java邮件发送解决ssl及邮件中文乱码org.apachemons.mail.EmailException: Sending the email to the following server failed : smtp.qiye.163

Java邮件发送解决ssl及邮件中文乱码

Java邮件发送解决ssl及邮件中文乱码

org.apachemons.mail.EmailException: Sending the email to the following server failed : smtp.qiye.163:25 Caused by: javax.mail.AuthenticationFailedException: 535 5.7.0 ERR.LOGIN.NONSSL

导入jar包 compile('org.apachemons:commons-email:1.3.3')

代码语言:javascript代码运行次数:0运行复制
/**
     * 发送邮件给指定的人
     *
     * @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 

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。 原始发表:2022-02-16,如有侵权请联系 cloudcommunity@tencent 删除乱码异常javasslstring

发布者:admin,转转请注明出处:http://www.yc00.com/web/1754988645a5224447.html

相关推荐

  • Java邮件发送解决ssl及邮件中文乱码

    Java邮件发送解决ssl及邮件中文乱码org.apachemons.mail.EmailException: Sending the email to the following server failed : smtp.qiye.163

    1月前
    190

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信