简体   繁体   English

无法连接到SMTP主机:xxxx,端口:java中的25

[英]Could not connect to SMTP host: x.x.x.x, port: 25 in java

I cannot send email in Java, it throw Exception: Could not connect to SMTP host: xxxx, port: 25. 我无法使用Java发送电子邮件,它引发异常:无法连接到SMTP主机:xxxx,端口:25。

I telnet xxxx 25 OK and I sent email successfully in php code with the same host, port, user & password, so I don't think this issue due to network or firewall problems. 我使用telnet xxxx 25,然后以相同主机,端口,用户和密码的php代码成功发送了电子邮件,因此我不认为由于网络或防火墙问题而导致此问题。

In testing, I sent email OK in java with gmail server (smtp.gmail.com :465), but not with host: xxxx port 25. 在测试中,我使用gmail服务器(smtp.gmail.com:465)在Java中以电子邮件发送了OK,但未通过主机:xxxx端口25发送电子邮件。

This is my java code: HOST=xxxx 这是我的Java代码:HOST = xxxx

Properties mailServerProperties = System.getProperties();
mailServerProperties.put("mail.smtp.user", USER);
mailServerProperties.put("mail.smtp.host", HOST);
mailServerProperties.put("mail.smtp.port", 25);
mailServerProperties.put("mail.smtp.debug", "true");
mailServerProperties.put("mail.smtp.auth", "true");
mailServerProperties.put("mail.smtp.starttls.enable", "true");
mailServerProperties.put("mail.smtp.socketFactory.port", 25);
mailServerProperties.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");

javax.mail.Session getMailSession = javax.mail.Session.getDefaultInstance(mailServerProperties);
MimeMessage generateMailMessage = new MimeMessage(getMailSession);
generateMailMessage.setHeader("Content-Type", "text/plain; charset=UTF-8");
generateMailMessage.setSubject(subject, "UTF-8");
generateMailMessage.setFrom(new InternetAddress(ApiConstant.EMAIL, fromEmail, "UTF-8"));
generateMailMessage.addRecipients(Message.RecipientType.TO, toAddress);
generateMailMessage.addRecipients(Message.RecipientType.CC, ccAddress);
generateMailMessage.addRecipients(Message.RecipientType.BCC, bccAddress);

Multipart multipart = new MimeMultipart();
MimeBodyPart messagePart = new MimeBodyPart();
messagePart.setContent(content, "text/html; charset=UTF-8");
multipart.addBodyPart(messagePart);       
generateMailMessage.setContent(multipart);

logger.debug("Create transport");
Transport transport = getMailSession.getTransport("smtp");
transport.connect(HOST, 25, USER, PASS);
transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());
transport.close();

This is my php code, it worked. 这是我的php代码,它起作用了。

$mail = new PHPMailer();
$mail->Host = 'x.x.x.x';
$mail->Port = '25';
$mail->SMTPAuth = true;
$mail->Username = USER;
$mail->Password = PASS;
$mail->From = '.....';
$mail->FromName = '.....';

$mail->setLanguage('vi');
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
$mail->addAttachment(FILE_NAME);
$mail->addAddress('....');
$mail->Subject ="test";
$mail->Body = "test";
$mail->Body = $body;

Plz help me. 请帮我。

On some networks, IPv6 may be problematic. 在某些网络上,IPv6可能会出现问题。 Try running your app with the VM option 尝试使用VM选项运行您的应用

-Djava.net.preferIPv4Stack=true

ie

java -Djava.net.preferIPv4Stack=true -cp . MyClass

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法连接到SMTP主机:…,端口:25? - Could not connect to SMTP host: …, port: 25? grails:无法连接到SMTP主机:*********,端口:25 - grails : Could not connect to SMTP host: *********, port: 25 回复邮件时无法连接到SMTP主机:localhost,端口:25- - Could not connect to SMTP host: localhost, port: 25 - while REPLYing to mail Java Mail异常。 无法连接到SMTP主机:localhost,端口:25; - Java Mail Exception. Could not connect to SMTP host: localhost, port: 25; java.security.cert.CertificateException:找不到与IP地址xxxx匹配的使用者替代名称 - java.security.cert.CertificateException: No subject alternative names matching IP address x.x.x.x found 无法连接到SMTP主机:smtp8.net4india.com,端口:25; - Could not connect to SMTP host: smtp8.net4india.com, port: 25; 使用Java的电子邮件通知我可能会遇到错误,因为无法连接到SMTP主机:RELAY.MY.COM,端口:25,响应:421 - Email notification using java i can face error as Could not connect to SMTP host: RELAY.MY.COM, port: 25, response: 421 是否有x.25协议Java库? - Are there any x.25 protocol Java libraries? javax.mail.MessagingException:无法连接到SMTP主机:<主机名>端口:25响应:554 - javax.mail.MessagingException: Could not connect to SMTP host : <host name> port : 25 response: 554 如何使用 Camel FTP 处理“主机尝试数据连接 xxxx 与服务器 yyyy 不同”错误? - How to handle "Host attempting data connection x.x.x.x is not the same as server y.y.y.y" error with Camel FTP?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM