我正在使用这个库在我的大学发送电子邮件到目前为止我设法正确访问服务器并设置我的所有配置但是当我尝试发送电子邮件时我得到了这个错误我也尝试了从地址但服务器否认我的权利。谁能告诉我我该怎么办? 这是我的代码,上面是错误。
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SendanEmail {
public static void main(String[] args) {
final String username = "user";//THIS IS THE SUPPOSE USER I said I alredy got in the server
final String password = "pass";
Properties props = new Properties();
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.host", "smtp.estudiantes.uci.cu");
props.put("mail.smtp.port", "25");
props.put("mail.smtp.ssl.trust", "smtp.estudiantes.uci.cu");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
//message.setFrom(new InternetAddress("ccastro@estudiantes.uci.cu"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("ccastro@estudiantes.uci.cu"));
message.setSubject("Test");
message.setText("Text content in my email");
Transport.send(message);
System.out.println("Done and done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
这是该计划中的例外情况:
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: can't determine local email address
at sendanemail.SendanEmail.main(SendanEmail.java:55)
Caused by: javax.mail.MessagingException: can't determine local email address
at com.sun.mail.smtp.SMTPTransport.mailFrom(SMTPTransport.java:1640)
at com.sun.mail.smtp.SMTPTransport.sendMessage(SMTPTransport.java:1194)
at javax.mail.Transport.send0(Transport.java:254)
at javax.mail.Transport.send(Transport.java:124)
at sendanemail.SendanEmail.main(SendanEmail.java:50)
Java Result: 1