java - 如何查找特定 smtp.host 的 SMTP 端口?

标签 java smtp

如何查找特定 smtp 主机的 smtp 端口?

import java.util.Properties;

import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.PasswordAuthentication;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;

public class SendMailTLS {

    public static void main(String[] args) {

        final String username = "anthony.savarimut@slingmedia.com";
        final String password = "test";

        Properties props = new Properties();
        props.put("mail.smtp.auth", "true");
        props.put("mail.smtp.starttls.enable", "true");
        props.put("mail.smtp.host", "mail.echostar.com");
        props.put("mail.smtp.port", "9000");

        Session session = Session.getInstance(props,
          new javax.mail.Authenticator() {
            protected PasswordAuthentication getPasswordAuthentication() {
                return new PasswordAuthentication(username, password);
            }
          });

        try {

            Message message = new MimeMessage(session);
            message.setFrom(new InternetAddress("AnthonyRajS@antony.com"));
            message.setRecipients(Message.RecipientType.TO,
                InternetAddress.parse("antoalphi@gmail.com"));
            message.setSubject("Testing Subject");
            message.setText("Dear Mail Crawler,"
                + "\n\n No spam to my email, please!");

            Transport.send(message);

            System.out.println("Done");

        } catch (MessagingException e) {
            throw new RuntimeException(e);
        }
    }
}

是我的代码,但它抛出了这个异常,

Exception in thread "main" java.lang.RuntimeException: javax.mail.MessagingException: Exception reading response;
  nested exception is:
    java.net.SocketException: Connection reset
    at samples.SendMailTLS.main(SendMailTLS.java:47)
Caused by: javax.mail.MessagingException: Exception reading response;
  nested exception is:
    java.net.SocketException: Connection reset
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2153)
    at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:1912)
    at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:638)
    at javax.mail.Service.connect(Service.java:317)
    at javax.mail.Service.connect(Service.java:176)
    at javax.mail.Service.connect(Service.java:125)
    at javax.mail.Transport.send0(Transport.java:194)
    at javax.mail.Transport.send(Transport.java:124)
    at samples.SendMailTLS.main(SendMailTLS.java:42)
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at com.sun.mail.util.TraceInputStream.read(TraceInputStream.java:110)
    at java.io.BufferedInputStream.fill(Unknown Source)
    at java.io.BufferedInputStream.read(Unknown Source)
    at com.sun.mail.util.LineInputStream.readLine(LineInputStream.java:89)
    at com.sun.mail.smtp.SMTPTransport.readServerResponse(SMTPTransport.java:2131)

我确信它会在端口中出现问题。请帮我解决这个问题。

问候 托尼

最佳答案

SMTP 的默认端口是 25:

http://www.emailaddressmanager.com/tips/mail-servers.html

我的建议是您联系邮件服务器的管理员。

关于java - 如何查找特定 smtp.host 的 SMTP 端口?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10896797/

相关文章:

c# - "The remote certificate is invalid according to the validation procedure."使用 Gmail SMTP 服务器

java - org.hibernate.ObjectNotFoundException : No row with the given identifier exists

Java 格式化以获取最后计数

java - (Docker+SpringBoot+Mysql)Mysql连接被拒绝

java - 模组制作,在屏幕上绘制东西时崩溃?

c# - 指定的字符串不是电子邮件地址所需的格式。发送电子邮件时

当由于内部服务器错误而尝试向管理员发送电子邮件时,Django 无法正确启动TLS

java - Gmail 中的 SMTPSendFailedException 530,SMTP 失败而 IMAP 工作

c# - SmtpClient发送邮件

java - Eclipse 在 v. 2020-03 中生成 "source not found"