해결 방법 : Java 코드가 문제가되지 않았습니다. Postfix 서버가 로컬이 아닌 IP/호스트에서 온 전자 메일을 허용하도록 구성되지 않았습니다. IP는 mynetworks 변수의 main.cf에 추가되었습니다. 원래 게시물을 컨텍스트로 남겨 둡니다.잘못된 주소를 반환하는 Postfix; 454 <[email protected]> : 릴레이 액세스가 거부 됨 - 해결됨
사전 구성된 Postfix 서버를 사용하고 JavaMail을 사용하여 상호 작용합니다. 전자 메일 알림을 요청할 수있는 외부 도메인으로 전자 메일 알림을 보내려고합니다. 나는 JavaMail에 코드를 포함하는 방법을 실행하면
public void TestEmail() {
String to = "[email protected]";
String from = "[email protected]";
final String username = "user";
final String password = "password";
String host = "xxx.xxx.xxx.xxx";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject("Test Email");
message.setContent("This is a test email", "text/html");
Transport.send(message);
System.out.println("The test message was sent!");
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
, 나는 generalError: javax.mail.SendFailedException: Invalid Addresses; nested exception is: com.sun.mail.smtp.SMTPAddressFailedException: 454 4.7.1 <[email protected]>: Relay access denied
내가에서 보내는 메일을 테스트 할 수 있었다 얻을 : 여기
echo "This is the body" | mail -s "This is the subject" [email protected]
을 사용하고 있으며 테스트 인 박스에서 이메일을 받았습니다.
Postfix 서버의 모든 설정을 100 % 확신 할 수는 없지만 문제가있는 곳이 어디인지 의심 스럽지만 충분히 파고 들고 모든 것을 바꾸기에 익숙하지 않습니다. - 닐리. 그래서 어떤 도움을 주시면 감사하겠습니다.
감사합니다.
는 편집 :
String host = "xxx.xxx.xxx.xxx";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", host);
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props, null);
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(to));
message.setSubject("Test Email");
message.setContent("This is a test email", "text/html");
Transport transport = session.getTransport("smtp");
transport.connect(host, 587, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
System.out.println("The test message was sent!");
} catch (MessagingException e) {
System.out.println("Error: " + e);
e.printStackTrace();
throw new RuntimeException(e);
}
}
이것은이 있습니다 나는
Transport transport = session.getTransport("smtp");
transport.connect(host, 587, username, password);
transport.sendMessage(message, message.getAllRecipients());
transport.close();
코드의 전체 새로운 세트는 세션 생성에서 설정 한 Authenticator()
을 제거하고 권장 코드 블록으로 Transport.send()
교체 받은 오류 메시지를 변경했습니다. Unrecognized SSL message, plaintext connection?
고마워요! JavaMail FAQ에서 권장하는대로 변경했으며 JavaMail의 최신 버전 인 1.5.6을 사용하고 있습니다.적어도 지금은 다른 오류 메시지가 나타납니다. 인식 할 수없는 SSL 메시지, 일반 텍스트 연결? 그래서 내가 여기서 알아낼 수있는 것을 볼 것입니다. 다시 한 번 감사드립니다! – the3rdNotch
현재 사용중인 코드로 게시물을 업데이트하십시오. 오류 메시지는 SSL이 아닌 일반 텍스트를 사용하는 서버 포트에 SSL로 연결 중임을 나타냅니다. 위 코드는 올바른 것으로 보입니다 (시작점을 사용함). 그래서 다른 것을 변경해야합니다. –
원래 게시물에 업데이트 된 코드가 추가되었습니다. – the3rdNotch