【发布时间】:2015-05-15 06:44:30
【问题描述】:
电子邮件在 windows server 2008 中正常工作,但是当我更改为 windows server 2012 时,它导致了这个错误。
SystemException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.sendgrid.net, port: 25; nested exception is: java.net.SocketException: Permission denied: connect
我已经对此进行了谷歌搜索,他们告诉 -Djava.net.preferIPv4Stack=true,将此条目放在 jvm 系统属性中,并要求禁用防病毒软件。两者都没有奏效。我也尝试联系 ISP 打开 25 端口,现在 25 端口正在监听。这是我的代码。
Properties props = new Properties();
props.put("mail.transport.protocol", "smtp");
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.port", 25);
props.put("mail.smtp.auth", "true");
SMTPAuthenticator auth = new SMTPAuthenticator();
Session mailSession = Session.getDefaultInstance(props, auth);
mailSession.setDebug(true);
Transport transport = mailSession.getTransport();
MimeMessage message = new MimeMessage(mailSession);
//read the Template and replace values using Velocity Engine
String text = messageContent;
message.setFrom(new InternetAddress(from));
message.setSubject(subject);
transport.connect();
transport.sendMessage(message, message.getRecipients(Message.RecipientType.TO));
transport.close();
我正在使用 sendgrid、java8、struts 2 和 apache tomcat 8。你是我最后的希望,请帮助我。提前致谢。
【问题讨论】:
-
您确定您的凭据正确吗?您可以将它们注销以进行验证吗?可以试试 587 端口吗?
-
@eddiezane 是的,我的凭据是正确的。我尝试了其他端口,但它无法正常工作。