I am sending Outlook mail using Java code. I am facing issues with adding sensitivity labels like confidential, private, public, etc.
Below is the POC I am using.
and also the output I am getting.
JavaCopy
import java.util.Properties;
import javax.mail.Message;
import javax.mail.MessagingException;
import javax.mail.Session;
import javax.mail.Transport;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
public class SmtpExample {
public static void main(String[] args) throws MessagingException {
String to = "dummy";
String userEmail = "dummy";
String accessToken = "dummy";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.transport.protocol", "smtp");
props.put("mail.imap.sasl.enable", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.auth.mechanisms", "XOAUTH2");
props.put("mail.smtp.auth.login.disable", "true");
props.put("mail.smtp.auth.plain.disable", "true");
props.put("mail.debug.auth", "true");
Authenticator auth = new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(userEmail,accessToken );
}
};
Session session = Session.getInstance(props, auth);
Transport transport = session.getTransport("smtp");
transport.connect(smtpHost, port, userEmail,
accessToken);;
session.setDebug(true);
session.setDebug(true);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(userEmail));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("Hello");
message.setText("Hello Testing!");
message.addHeader("Sensitivity", "Confidential");
Transport.send(message);
System.out.println("message sent successfully...");
} catch (MessagingException e) {
e.printStackTrace();
}
}
}
The message is sent successfully but the issues I am facing are :
- I am not getting any confidential tags or extra security labels.
- Could you tell me how to do the same with UI.
Please check the POC and Tell me if is there anything wrong.