I am trying to send email to [email protected] via domain-com.mail.protection.outlook.com (Office 365 direct send),
below is my code,
void sendEmail(InternetAddress sender, List<InternetAddress> recipients, String subject, String body,
@Nullable BodyPart optAttachment,
XgemailDirectionEnum direction = XgemailDirectionEnum.INBOUND,
Optional<String> optionalEnvelopeSenderAddress = Optional.empty())
{
final Properties properties = new Properties(_defaultProperties)
for (InternetAddress recipient : recipients)
{
if (optionalEnvelopeSenderAddress.isPresent())
{
properties.put("mail.smtp.from", optionalEnvelopeSenderAddress.get())
}
Session session
properties.put("mail.smtp.host", domain-com.mail.protection.outlook.com)
properties.put("mail.smtp.port", 25)
properties.put("mail.debug", "true")
session = Session.getInstance(properties)
Message message = new MimeMessage(session)
message.setFrom(sender)
message.setRecipients(
Message.RecipientType.TO,
recipient as InternetAddress[]
)
message.setSubject(subject)
message.setText(body)
Transport.send(message)
}
I tried adding properties properties.put("mail.smtp.starttls.enable", "true") also, but no luck.
I am getting following error
com.sun.mail.util.MailConnectException: Couldn't connect to host, port: domain-com.mail.protection.outlook.com, 25; timeout -1
Following is mail.debug log
DEBUG: getProvider() returning javax.mail.Provider[TRANSPORT,smtp,com.sun.mail.smtp.SMTPTransport,Oracle]
DEBUG SMTP: useEhlo true, useAuth false DEBUG SMTP: trying to connect to host "domain-com.mail.protection.outlook.com", port 25, isSSL false