oracle ssl发送邮件,使用javax.mail发送带有ssl的电子邮件

我想使用gmail作为smtp服务器发送电子邮件.

这是我的代码,我没有让它工作……

运行testSettings()后,我得到调试输出,然后它就停止了.没有超时,没有错误,没有……

public void testSettings() {

final String username = Settings.get("benutzername");

final String password = Settings.get("passwort");

Properties props = new Properties();

props.put("mail.transport.protocol", "smtps");

props.put("mail.smtp.starttls.enable", "true");

props.put("mail.smtp.socketFactory.port", Settings.get("port"));

props.put("mail.smtp.socketFactory.class",

"javax.net.ssl.SSLSocketFactory");

props.put("mail.smtp.auth", "true");

props.put("mail.smtp.host", Settings.get("server"));

props.put("mail.smtp.port", Settings.get("port"));

props.put("mail.smtp.timeout", "10000");

props.put("mail.smtp.ssl.checkserveridentity", "false");

props.put("mail.smtp.ssl.trust", "*");

props.put("mail.smtp.connectiontimeout", "10000");

props.put("mail.smtp.debug", "true");

props.put("mail.smtp.socketFactory.fallback", "false");

Session session = Session.getInstance(props,

new javax.mail.Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {

return new PasswordAuthentication(username, password);

}

});

session.setDebug(true);

try {

Message message = new MimeMessage(session);

message.setFrom(new InternetAddress("myemail@gmail.com"));

message.setRecipients(Message.RecipientType.TO,

InternetAddress.parse("myemail@gmail.com"));

message.setSubject("Testing Subject");

message.setText("test");

Transport transport = session.getTransport("smtps");

transport.send(message);

// Transport.send(message);

System.out.println("Done");

} catch (MessagingException e) {

// throw new RuntimeException(e);

}

}

DEBUG: setDebug: JavaMail version 1.4.7

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtps,com.sun.mail.smtp.SMTPSSLTransport,Oracle]

DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: useEhlo true, useAuth true

DEBUG SMTP: trying to connect to host "smtp.gmail.com", port 587, isSSL false

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值