아파치 제임스를 사용하여 이메일을 보내려고하지만 이메일이 전송되지 않습니다. 아래는 제 코드입니다.아파치 제임스를 사용하는 이메일 전송이 작동하지 않습니다.
import java.util.*;
import javax.mail.*;
import javax.mail.internet.*;
public class test {
public static void main(String args[]) throws Exception {
String user = "test";
String password = "test";
String fromAddress = "[email protected]";
String toAddress = "[email protected]";
Properties properties = new Properties();
properties.put("mail.smtp.host", "localhost");
properties.put("mail.smtp.port", "25");
properties.put("mail.smtp.username", user);
properties.put("mail.smtp.password", password);
properties.put("mail.transport.protocol", "smtp");
Session session = Session.getDefaultInstance(properties, null);
try
{
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress(fromAddress));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(toAddress));
message.setSubject("Email from our JAMEs");
message.setText("hiiiiii!!");
Transport.send(message);
System.out.println("Email sent");
}
catch (MessagingException e)
{
e.printStackTrace();
}
}
}
또한 테스트 사용자 암호를 갖는 테스트 아파치 제임스 첨가된다. 너를 친절하게 나를 도와 달라.
사실'localhost'에서 메일 릴레이를 실행하고 있습니까? – Perception
글쎄, 만약 당신이 이미 알고 있지 않다면 그 대답은 아마도 아니오 일 것이다. 그러나 로컬 호스트 인 포트 25로 telnet으로 테스트 할 수 있습니다. 하나가 실행 중이면 연결할 수 있고 메일 서버의 이름을 인쇄해야합니다. 명령 셸에서 로컬 에코를 사용하도록 설정하십시오. – Perception
또한 예외 전체가 던져지고 있는지 확인하기 위해 전체 주 메서드 주위에 try/catch 절을 넣을 수도 있습니다. –