I usually use it this way with java mail
Properties propertie = new Properties();
propertie.put("mail.transport.protocol", "smtp");
propertie.put("mail.smtp.host", "smtp.live.com");
propertie.put("mail.smtp.socketFactory.port", "587");
propertie.put("mail.smtp.socketFactory.fallback", "false");
propertie.put("mail.smtp.starttls.enable", "true");
propertie.put("mail.smtp.auth", "true");
propertie.put("mail.smtp.port", "587");
session = Session.getDefaultInstance(propertie,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication("[email protected]", "suasenha");
}
});
I believe it is just problem on the host, try to change the
smtp-mail.outlook.com
for
smtp.live.com
.
HtmlEmail email = new HtmlEmail();
email.setHostName("smtp.live.com");
email.setSslSmtpPort(587);
email.setAuthenticator(new DefaultAuthenticator("[email protected]", "suasenha"));
Edited
Example using the javaMail
public class SendMail {
public static void main(String[]args) throws IOException {
final String username = "[email protected]";
final String password = "suasenha";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
props.put("mail.smtp.host", "outlook.office365.com");
props.put("mail.smtp.port", "587");
Session session = Session.getInstance(props,
new javax.mail.Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
try {
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("seuemail@outlook"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("emaildestino@..."));
message.setSubject("Testando");
message.setText("Olá");
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}
Good morning buddy, can you give me a more complete example of this situation?
– DevAgil
Good morning, I edited the reply by adding an example of sending an email using javamail
– brow-joe