1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > java mail 端口号_使用Javamail连接到Gmail smtp服务器将忽略指定的端口并尝试使用25...

java mail 端口号_使用Javamail连接到Gmail smtp服务器将忽略指定的端口并尝试使用25...

时间:2021-08-22 19:22:11

相关推荐

java mail 端口号_使用Javamail连接到Gmail smtp服务器将忽略指定的端口并尝试使用25...

我试图使用javamail在groovy脚本通过gmail发送一封电子邮件。我已经看了很多地方在网上,一直无法得到它的工作到目前为止。我在运行我的脚本时遇到的错误是:

DEBUG SMTP: useEhlo true, useAuth false

DEBUG SMTP: trying to connect to host "", port 25, isSSL false

Caught: javax.mail.SendFailedException: Send failure (javax.mail.MessagingException: Could not connect to SMTP host: , port: 25 (.ssl.SSLException: Unrecognized SSL message, plaintext connection?))

似乎是尝试使用端口25,即使我已经指定它应该使用端口587.有谁知道可能是什么导致这个问题,我使用telnet连接到端口587的smtp服务器,和thunderbird使用端口587与STARTTLS安全,并能够成功地使用smtp服务器发送邮件。这告诉我,它不是一个阻塞的端口或连接问题。这里是我用来尝试和发送电子邮件的代码:

import javax.mail.*

import javax.mail.internet.*

private class SMTPAuthenticator extends Authenticator

{

public PasswordAuthentication getPasswordAuthentication()

{

return new PasswordAuthentication('email@', 'password');

}

}

def d_email = "email@",

d_password = "password",

d_host = "",

d_port = "587", //465,587

m_to = "email@",

m_subject = "Testing",

m_text = "This is a test."

def props = new Properties()

props.put("mail.smtp.user", d_email)

props.put("mail.smtp.host", d_host)

props.put("mail.smtp.port", d_port)

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

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

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

props.put("mail.smtp.socketFactory.port", d_port)

props.put("mail.smtp.socketFactory.class", ".ssl.SSLSocketFactory")

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

def auth = new SMTPAuthenticator()

def session = Session.getInstance(props, auth)

session.setDebug(true);

def msg = new MimeMessage(session)

msg.setText(m_text)

msg.setSubject(m_subject)

msg.setFrom(new InternetAddress(d_email))

msg.addRecipient(Message.RecipientType.TO, new InternetAddress(m_to))

Transport.send(msg)

任何帮助将不胜感激。提前致谢!

-Bryan

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。