如何使用 javamail 和 postfix/dovecot 发送邮件

how to send mail with javamail and postfix/dovecot

嘿,我最近一直在尝试使用我的 postfix/dovecot 服务器通过 javamail 发送邮件。

首先,我使用本教程设置我的邮件服务器:https://upcloud.com/community/tutorials/secure-postfix-using-lets-encrypt/

我可以在本地机器上正常收发邮件,但在 java:

中使用此代码
String to = "somemail@gmail.com";
String from = "somemail@example.com";
final String username = "somemail@example.com"; // somemail does the same
final String password = "password";

String host = "mail.example.com";

Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable","true"); // same output with mail.smtp.ssl.enable
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", 25);
props.put("mail.smtp.user", username);
props.put("mail.smtp.password", password);

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

session.setDebug(true);
try {
    Message message = new MimeMessage(session);

    message.setFrom(new InternetAddress(from));

    message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));

    message.setSubject("Testing Subject");

    message.setText("Hello, this is sample for to check send " + "email using JavaMailAPI ");
    Transport.send(message);

    System.out.println("Sent message successfully....");

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

这是堆栈跟踪:https://pastebin.com/FTHmrQ2T(无法 post 因为它看起来像垃圾邮件)这是 nmap:

PORT    STATE SERVICE
22/tcp  open  ssh
25/tcp  open  smtp
110/tcp open  pop3
143/tcp open  imap
993/tcp open  imaps
995/tcp open  pop3s

有人知道发生了什么/如何解决吗?我真的需要这方面的帮助:/ 谢谢^^

我找到了解决办法! 您只需要取消注释“/etc/postfix/master.cf”中的“#submission inet n – n – – smtpd”! 现在一切正常!