我正在尝试使用Java(Java 10)发送电子邮件,但出现此错误:
javax.mail.SendFailedException: No recipient addresses
at javax.mail.Transport.send0(Transport.java:154)
at javax.mail.Transport.send(Transport.java:124)
at Mail.mandaMail(Mail.java:282)
at View$1.actionPerformed(View.java:68)
[...]
Process finished with exit code 0
这是在行“ 282”处发生类抛出错误的代码
我使用的变量:
mittente =“ *************** @ ******。com”
密码 = ******
主机 =邮件。 mydomain .com
目的地 = ****** @ gmail.com
我正在使用 Aruba 邮件服务器,但是我认为它的配置不正确
public void mandaMail(String destinatario) throws MessagingException, NoClassDefFoundError {
//Get the session object
Properties props = new Properties();
props.put("mail.smtp.host",host);
props.put("mail.smtp.auth", true);
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(mittente,password);
}
});
//Compose the message
Message message = new Message(session)(**Overriding all the methods*)
message.setFrom(new InternetAddress(mittente));
//A:
message.addRecipient(Message.RecipientType.TO,new InternetAddress(destinatario, true));
//CC
message.addRecipient(Message.RecipientType.CC, new InternetAddress());
message.setSubject("PFSistemi -"+intervento.toString());
message.setText(this.contenuto.toString());
//send the message
Transport.send(message);
System.out.println("message sent successfully...");
}
也许这个问题是由于重写了 Message 类的所有方法所致,所以我使用了该类,因为 MimeMessage 类给了我很多人无法解决的问题(笑)