2

我正在尝试通过我的 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)
4

1 回答 1

1

也许是 Java 的答案:为什么 SSL 握手会给出“无法生成 DH 密钥对”异常?帮助你。使用 Java 1.7.08 或更高版本应该可以解决问题。

于 2013-05-07T21:10:22.000 回答