有关javamail的错误AuthenticationFailedException(急)

qiron 2002-11-18 08:36:03
我想请问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 );
}
}
...全文
119 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
qiron 2002-11-29
  • 打赏
  • 举报
回复
这是设置什么内容的啊?
lwd01 2002-11-29
  • 打赏
  • 举报
回复
用户认证通过后可以收发信

public class PopupAuthenticator extends Authenticator{
String username=null;
String password=null;
public PopupAuthenticator(){}

public PasswordAuthentication performCheck(String user,String pass){
username = user;
password = pass;
return getPasswordAuthentication();
}

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}

}

Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth","true");
Session sendMailSession;
Store store;
Transport transport;
PopupAuthenticator popAuthenticator = new PopupAuthenticator();
PasswordAuthentication pop = popAuthenticator.performCheck("username","password");
sendMailSession=Session.getInstance(props,popAuthenticator);

Message newMessage = new MimeMessage(sendMailSession);
newMessage.setFrom(new InternetAddress(request.getParameter("from")));
newMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(request.getParameter("to")));
newMessage.setSubject(request.getParameter("subject"));
newMessage.setSentDate(new Date());
newMessage.setText(request.getParameter("body"));
transport = sendMailSession.getTransport("smtp");
transport.send(newMessage);
laizg 2002-11-28
  • 打赏
  • 举报
回复
怎么你那里不用设置“text/plain”之类的东东呢》?
qiron 2002-11-20
  • 打赏
  • 举报
回复
是啊,是不是和smtp.163.com这个邮件服务器有关,我试过用sina和yeah的有服务器也是。
zxhong 2002-11-20
  • 打赏
  • 举报
回复
恩?
确定你填的条件都存在,正确!
qiron 2002-11-20
  • 打赏
  • 举报
回复
不对阿。明明没有问题的,我自己去试过了阿。账号和密码没有问题
zxhong 2002-11-20
  • 打赏
  • 举报
回复
你的帐号或密码不正确

81,094

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧