Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/341.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在WebLogic上使用Gmail和TLS发送电子邮件_Java_Email_Ssl - Fatal编程技术网

Java 在WebLogic上使用Gmail和TLS发送电子邮件

Java 在WebLogic上使用Gmail和TLS发送电子邮件,java,email,ssl,Java,Email,Ssl,以下是我用来发送电子邮件的代码: Properties smtpProps = new Properties(); smtpProps.load(getClass().getResourceAsStream(SMTP_PROPERTIES_FILE)); // Load from email properties Properties emailProps = new Properties(); emailProps.load(getClass().ge

以下是我用来发送电子邮件的代码:

    Properties smtpProps = new Properties();
    smtpProps.load(getClass().getResourceAsStream(SMTP_PROPERTIES_FILE));

    // Load from email properties
    Properties emailProps = new Properties();
    emailProps.load(getClass().getResourceAsStream(EMAIL_PROPERTIES_FILE));

    // We could setup a mail session from the Weblogic server
    Session session = Session.getInstance(smtpProps, null);

    // Create a new message
    MimeMessage msg = new MimeMessage(session);

    // Set the from and to
    msg.setFrom(new InternetAddress(emailProps.getProperty(EMAIL_PROPERTY_NAME)));
    msg.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));

    // Message content
    msg.setSubject(subject);
    msg.setText(message, MESSAGE_ENCODING);

    // Send the email
    String host     = smtpProps.getProperty(HOST_PROPERTY_NAME);
    String username = emailProps.getProperty(EMAIL_PROPERTY_NAME);
    String password = emailProps.getProperty(PASSWORD_PROPERTY_NAME);

    Transport transport = session.getTransport("smtp");
    transport.connect(host, 587, username, password);
    transport.sendMessage(msg, msg.getAllRecipients());
以及我正在使用的属性文件:

mail.smtp.host=smtp.gmail.com
mail.smtp.port=587
mail.smtp.auth=true
mail.smtp.starttls.enable=true
mail.protocol.ssl.trust=smtp.gmail.com
当我在WebLogic上运行它(作为webservice)时,我得到以下错误:

javax.mail.MessagingException: Can't send command to SMTP host;   nested exception is:  javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
我做错了什么?
谢谢

我想是的,你需要将gmail的证书添加到你的webSphere中。但是通过添加这个:mail.protocol.ssl.trust=smtp.gmail.com不是必须的吗?你也需要这个,但是你需要下载gmail的证书并添加到webSphere控制台中,我的PC中现在没有webSphere来逐步向你展示。对不起:(也许对你有用