Answer the question
In order to leave comments, you need to log in
How to send email from java code?
Properties p = new Properties();
p.put("mail.smtp.host", "smtp.gmail.com");
p.put("mail.smtp.socketFactory.port", 465);
p.put("mail.smtp.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
p.put("mail.smtp.auth", "true");
p.put("mail.smtp.port", 465);
Session s = Session.getInstance(p,
new javax.mail.Authenticator(){
protected PasswordAuthentication getPasswordAuthentication(){
return new PasswordAuthentication("[email protected]", "root");
}
}
);
Message message = new MimeMessage(s);
try {
message.setFrom(new InternetAddress("[email protected]"));
message.setRecipient(Message.RecipientType.TO, new InternetAddress("[email protected]"));
message.setSubject("Тема письма");
message.setText("Сообщение в письме");
Transport.send(message);
System.out.println("Письмо успешно отправлено");
} catch (MessagingException e) {
System.out.println("Письмо не отправилось");
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question