javax.mail.MessagingException:553 authentication is required,smtp2,DNGowLBbuQPU2mFIeZiQBw==.59922S2 1214372564 什么毛病?我程序代码:DataInputStream dis = new DataInputStream(request.getInputStream()) ;String send = dis.readUTF() ;String subje
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/25 12:36:55
javax.mail.MessagingException:553 authentication is required,smtp2,DNGowLBbuQPU2mFIeZiQBw==.59922S2 1214372564 什么毛病?我程序代码:DataInputStream dis = new DataInputStream(request.getInputStream()) ;String send = dis.readUTF() ;String subje
javax.mail.MessagingException:553 authentication is required,smtp2,DNGowLBbuQPU2mFIeZiQBw==.59922S2 1214372564 什么毛病?
我程序代码:
DataInputStream dis = new DataInputStream(request.getInputStream()) ;
String send = dis.readUTF() ;
String subject = dis.readUTF();
String content = dis.readUTF() ;
System.out.println(send+" -- "+subject+" -- "+content);
try {
Properties props = System.getProperties() ;
props.put("mail.smtp.host",host);
Session session = Session.getDefaultInstance(props,new MyAuthenticator()) ;
MimeMessage message = new MimeMessage(session) ;
message.setFrom(new InternetAddress(from)) ;
message.addRecipient(Message.RecipientType.TO,new
InternetAddress(send));
message.setSubject(subject) ;
message.setText(content) ;
Store store = session.getStore("pop3") ;
store.connect("pop3.163.com","****","****");
Transport.send(message) ;
} catch (Exception e) {
e.printStackTrace();
} finally{
dis.close() ;
}
javax.mail.MessagingException:553 authentication is required,smtp2,DNGowLBbuQPU2mFIeZiQBw==.59922S2 1214372564 什么毛病?我程序代码:DataInputStream dis = new DataInputStream(request.getInputStream()) ;String send = dis.readUTF() ;String subje
这是javamail的验证方法中的一种
改写Authenticator的getPasswordAuthentication()方法
private class Authenticator extends javax.mail.Authenticator
{
public PasswordAuthentication getPasswordAuthentication()
{
String un = user;
String pw = password;
return new PasswordAuthentication(un,pw);
}
}
应用这个之前需要设置
props.put( "mail.smtp.auth ","true ");
然后
Authenticator auth = new Authenticator();
Session mailSession = Session.getInstance(props,auth);
还有一种方法是在Transport中设置
Transport transport = mailSession.getTransport( "smtp ");
transport.connect( "mail.smtp.auth ","username ","password ");
transport.sendMessage(mimeMsg,maillist);
transport.close();
* sorze
* sorze
* 等级:
transport.connect( "mail.smtp.auth ","username ","password "); “mail.smtp.auth”应改为"smtp.163.com"或者类似的,其实写成这样就可以了transport.connect( "username ","password "); mail.smtp.host在propperties中就设置了