1
java 메일 API를 통해 office365를 사용하여 메일을 보내려고합니다. 내 코드입니다 - 내가 같이 치어에서 메일 및 활성화에 대한 의존성을 추가 한MAIL FROM [MA1PR01CA0086.INDPRD01.PROD.OUTLOOK.COM] 중에 익명 메일을 보내도록 클라이언트가 인증되지 않았습니다.
public void sendMail() {
String to = [email protected];
String subject = "subject";
String msg ="email text....";
final String from = [email protected];
final String password = "password";
Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.host", "smtp.office365.com");
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "587");
props.put("mail.debug", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.socketFactory.fallback", "false");
Session session = Session.getDefaultInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(from,password);
}
});
Transport transport = null;
try {
transport = session.getTransport("smtp");
} catch (NoSuchProviderException e) {
e.printStackTrace();
}
InternetAddress addressFrom = null;
try {
addressFrom = new InternetAddress(from);
} catch (AddressException e) {
e.printStackTrace();
}
try {
MimeMessage message1 = new MimeMessage(session);
message1.setSender(addressFrom);
message1.setSubject(subject);
message1.setContent(msg, "text/plain");
message1.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
transport.connect();
Transport.send(message1);
transport.close();
} catch(Exception e) {
e.printStackTrace();
}
}
:
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.5</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
그러나 나는이 예외를 얻고있다.
com.sun.mail.smtp.SMTPSendFailedException: 530 5.7.57 SMTP;
Client was not authenticated to send anonymous mail during MAIL FROM [MA1PR01CA0086.INDPRD01.PROD.OUTLOOK.COM]