Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法在没有授权的情况下通过邮件传输代理发送电子邮件(获取错误421)_Java_Email - Fatal编程技术网

Java 无法在没有授权的情况下通过邮件传输代理发送电子邮件(获取错误421)

Java 无法在没有授权的情况下通过邮件传输代理发送电子邮件(获取错误421),java,email,Java,Email,我试图在未经授权的情况下用MTA发送电子邮件。我浏览了这个网站,得到了以下代码: String emailTo = "test@example.com"; //In my real code I use actual email adress String body = "This is test message"; UUID uuid = UUID.randomUUID(); Instant sentDate = Ins

我试图在未经授权的情况下用MTA发送电子邮件。我浏览了这个网站,得到了以下代码:

    String emailTo = "test@example.com"; //In my real code I use actual email adress
    String body = "This is test message";

    UUID uuid = UUID.randomUUID();
    Instant sentDate = Instant.now();

    Properties props = new Properties();
    props.put("mail.smtp.auth","false");
    props.put("mail.smtp.starttls.enable", "true");

    props.put("mail.mime.charset", "utf-8");
    props.put("mail.smtp.host", mtaHost); //mtaHost is our mail transfer agent
    props.put("mail.smtp.port", "25");

    Session session = Session.getInstance(props);

    
    MimeMessage msg = new MimeMessage(session);
    msg.setHeader("Content-Type", "text/html;charset=utf-8");
    Transport transport = null;
    try {
        msg.setFrom(new InternetAddress(emailFrom));
        msg.setRecipient(Message.RecipientType.TO, new InternetAddress(emailTo));
       
            msg.setSubject("Testing send");
        

        BodyPart messageBodyPart = new MimeBodyPart();
        Multipart multipart = new MimeMultipart();

        messageBodyPart.setContent(body, MSG_TYPE);
        multipart.addBodyPart(messageBodyPart);


        // Send the complete message parts
        msg.setContent(multipart);

        transport = session.getTransport("smtp");
            transport.connect();
        transport.sendMessage(msg, msg.getAllRecipients());

    } catch (MessagingException | IOException e) {
        log.error("Error when send email by smtp: {}", e.toString());
    }
但当我尝试使用上述代码发送消息时,我得到错误: 无法连接到SMTP主机,端口:25,响应:421

我检查了这个主机,它确实正常发送电子邮件:


有人能告诉我我做错了什么吗?

你能修复标题吗?当你说你的电子邮件已经发送时,只有你的客户说它没有发送错误。所以这有点矛盾,不清楚你的实际问题是什么。