我正在尝试通过我的 java 应用程序发送电子邮件。我正在尝试从托管服务提供商 (cyberhost.in) 提供的电子邮件帐户发送电子邮件。每当我运行应用程序时,我都会收到一个 ssl 异常。
1)代码
public class Email {
public static void main(String[] args) throws UnsupportedEncodingException {
Properties props = new Properties();
props.put("mail.smtp.host", "v1.cyberns.net");
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,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("admin@heyywassup",
"********");
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("admin@heyywassup.com",
"heyywassup"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("amlan@ymail.com"));
message.setSubject("Testing Subject");
message.setText("Dear Mail Crawler,"
+ "\n\n No spam to my email, please!");
Transport.send(message);
System.out.println("Done");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
2)异常
>>>>>Sending data QUIT<<<<<<
Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
at com.bean.Email.main(Email.java:47)
Caused by: javax.mail.MessagingException: javax.net.ssl.SSLException: Connection has been shutdown: javax.net.ssl.SSLException: java.lang.RuntimeException: Could not generate DH keypair
at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.sendLine(SMTPTransport.java:1702)
at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.sendQuit(SMTPTransport.java:1459)
at org.apache.geronimo.javamail.transport.smtp.SMTPTransport.close(SMTPTransport.java:732)
at javax.mail.Transport.send(Transport.java:144)
at javax.mail.Transport.send(Transport.java:48)
at com.bean.Email.main(Email.java:42)