电子邮件在Windows Server 2008中正常工作,但当我更改为Windows Server 2012时,其导致此错误。无法连接到SMTP主机权限被拒绝:连接
SystemException: javax.mail.MessagingException: Could not connect to SMTP host: smtp.sendgrid.net, port: 25; nested exception is: java.net.SocketException: Permission denied: connect
我用Google搜索关于这一点,他们告诉-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,支柱2和Apache Tomcat 8.You是我最后的希望,请帮我这一点。提前致谢。
你确定你的凭证是正确的吗?你可以注销它们来验证吗?你可以尝试端口587? – eddiezane
@eddiezane是的,我的凭据是正确的。我尝试了其他港口,它不工作。 – Subash