有关javamail的错误AuthenticationFailedException(急)

qiron qiron 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
我想请问AuthenticationFailedException错误出现是什么引起的,下面是一个利用javamail发送附件的源程序。

package Mybean;
import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
import javax.activation.*;

public class AttachExample {
public void postemail(String tomail, String fileurl)
throws Exception {
String host ="smtp.163.com" ;
String from ="*****@163.com";
String to = tomail;
String fileAttachment = fileurl; //附件地址

// Get system properties
Properties props = System.getProperties();
Transport transport;

// Setup mail server
props.put("mail.smtp.host", host);
props.put("mail.smtp.auth", "true");

// Get session
Session session =
Session.getInstance(props, null);

transport = session.getTransport("smtp");
transport.connect("smtp.163.com","*****","****");

// Define message
MimeMessage message =
new MimeMessage(session);
message.setFrom(
new InternetAddress(from));
message.addRecipient(
Message.RecipientType.TO,
new InternetAddress(to));
message.setSubject(
"Here is Javacert!");

// create the message part
MimeBodyPart messageBodyPart =
new MimeBodyPart();

//fill message
messageBodyPart.setText("your cert");

Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);

// Part two is attachment
messageBodyPart = new MimeBodyPart();
DataSource source =
new FileDataSource(fileAttachment);
messageBodyPart.setDataHandler(
new DataHandler(source));
messageBodyPart.setFileName(fileAttachment);
multipart.addBodyPart(messageBodyPart);

// Put parts in message
message.setContent(multipart);

// Send the message
Transport.send( message );
}
}
...全文
评论 7
收藏 已收藏
分享
返回顶部
qiron
Web 开发 81,108 成员 341,721 内容