我有一个代码,它始终通过邮件pec发送到Aruba上。 有一次,它不再起作用了。当我编译时,它返回:
Exception reading response
Exception reading response
Exception reading response
Exception reading response
Exception reading response
Exception reading response
Exception reading response
Exception reading response
Exception reading response
使用嗅探程序,我发现问题与“认证未知”有关。
这是我的代码:
//********************************************************
public static boolean sendMail(String Messaggio, String mailDest) {
boolean stato = true;
try {
stato = true;
DataHandler dh = null;
Properties props = System.getProperties();
props.put("mail.smtp.host", Main.conf.getSmtp());
//attivare pec
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
Session session = Session.getDefaultInstance(props, authenticator );
javax.mail.Message message = new MimeMessage(session);
InternetAddress from = new InternetAddress(Main.conf.getMittenteMail());
InternetAddress to[] = InternetAddress.parse(mailDest);
message.setFrom(from);
message.setRecipients(javax.mail.Message.RecipientType.TO, to);
message.setSubject("AVVISO DI SCADENZA RIBA");
message.setSentDate(new Date());
// NUOVA GESTIONE MAIL : Testo + Allegato
Multipart multipart = new MimeMultipart();
// crea la parte testuale
BodyPart messageBodyPart1 = new MimeBodyPart();
messageBodyPart1.setContent(Messaggio.toString(),"text/html");
// messageBodyPart1.setText(Messaggio);
// Crea l'allegato , disattivata.
// DataSource source = new FileDataSource(file);
//BodyPart messageBodyPart2 = new MimeBodyPart();
// messageBodyPart2.setContent("<b>Sollecito Riba:<\b>", "text/html");
// mp.addBodyPart(bpHTML)
// messageBodyPart2.setDataHandler(new DataHandler(source));
/*File fFile = new File("C:\\folder\\prova.txt");
DataSource source = new FileDataSource(fFile); ALLEGATO
dh = new DataHandler(source);
messageBodyPart2.setDataHandler(dh);
messageBodyPart2.setFileName(fFile.getName());
*/
// aggiunge le parti all'oggetto multipart
//multipart.addBodyPart(messageBodyPart2);
multipart.addBodyPart(messageBodyPart1); //html
//multipart.addBodyPart(messageBodyPart2);
// imposta come contenuto del messaggio l'oggetto multipart
message.setContent(multipart);
// Transport.send(message);
// FINE NUOVA GESTIONE: Testo + Allegato
javax.mail.Transport.send(message);
} catch (MessagingException e) {
stato = false;
System.out.println(e.getMessage());
}
return stato;
}
我该怎么办?发生了什么?为什么它有效但不再有效?