anmin_ren
art_ren
2015-12-17 11:30

java代码0用163邮箱发送邮件时报这个错

5
  • 邮箱
  • java

com.sun.mail.smtp.SMTPSendFailedException: 553 authentication is required,163 smtp14,EsCowEBZ50rSm3JWmXF+AA--.3541S2 1450351570

java代码:

public class EmailTools {

public static boolean send(String to,String subject,String content){
    Properties props = new Properties();
    props.put("mail.transport.protocol", "smtp");

    props.put("mail.host","smtp.163.com");

    props.put("mail.from", "15234874536@163.com");

    props.put("mail.smtp.anth", true);

    Session session = Session.getDefaultInstance(props);

    session.setDebug(true);
    try {
        Transport transport = session.getTransport();

        // 连接邮件服务器,链接您的163、sina邮箱,用户名(不带@163.com,登录邮箱的邮箱账号,不是邮箱地址)、密码
        transport.connect("15234874536","*************");

        MimeMessage message = new MimeMessage(session);

        message.setSubject(subject);

        message.setContent(content,"text/html;charset=utf-8");

        message.setSentDate(new Date());

        transport.sendMessage(message, InternetAddress.parse(to));
        return true;
    } catch (NoSuchProviderException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (MessagingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return false;

}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    EmailTools email = new EmailTools();
    email.send("2747917518@qq.com","Hello World!", "你好你好你好你好你好");
}

}

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答

为你推荐