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

时间:2016-03-14 19:28:50

标签: java email ssl

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

Connection: keep-alive

我正在使用的属性文件:

Connection: close

当我在WebLogic上运行它(作为web服务)时,我收到以下错误:

    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());

我做错了什么? 感谢

0 个答案:

没有答案