javaMail 问题求解决
public class demo1 {
public static void main(String[] args) throws Exception {
//声明文件属性
Properties props=new Properties();
//设置需要验证(给提供用户名、密码)
props.setProperty("mail.smtp.auth", "true");
//发送邮件的方式
props.setProperty("mail.transport.protocol", "smtp");
//配置环境
Session session=Session.getInstance(props);
//开启调式模式
session.setDebug(true);
//制造邮件
Message msg=new MimeMessage(session);
//设置邮件内容
msg.setText(" 哈哈哈哈哈哈!");
//发送人邮件的地址
msg.setFrom(new InternetAddress("liao_15198041430@sohu.com"));
//发送邮件器
Transport trans=session.getTransport();
//发送人邮件的基本信息
trans.connect("smtp.sohu.com", 25, "liao_15198041430@sohu.com","******");
//发送邮件
trans.sendMessage(msg,new Address[]{new InternetAddress("15198041430@sina.cn")});
//关闭链接
trans.close();
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
下面是运行时报的错 怎么解决?
DEBUG: setDebug: JavaMail version 1.4ea
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.sohu.com", port 25, isSSL false
220 zw_71_37 ESMTP ready
DEBUG SMTP: connected to host "smtp.sohu.com", port: 25
EHLO LAPTOP-SFPC57PG
250-zw_71_37
250-AUTH PLAIN LOGIN
250 STARTTLS
DEBUG SMTP: Found extension "AUTH", arg "PLAIN LOGIN"
DEBUG SMTP: Found extension "STARTTLS", arg ""
DEBUG SMTP: Attempt to authenticate
AUTH LOGIN
334 VXNlcm5hbWU6
bGlhb18xNTE5ODA0MTQzMEBzb2h1LmNvbQ==
334 UGFzc3dvcmQ6
MTIzd280NTZjdW9s
主要是这里报错:
451 4.3.2 Internal server error
Exception in thread "main" javax.mail.AuthenticationFailedException
at javax.mail.Service.connect(Service.java:306)
at demo.demo1.main(demo1.java:64)