Properties props = new Properties();
props.put("mail.smtp.host", "SMTP_SERVER_ADDRESS");
props.put("mail.smtp.port", "SMTP_SERVER_PORT");
props.put("mail.smtp.auth", "true");
Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication("YOUR_EMAIL", "YOUR_PASSWORD");
}
});
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("sender@example.com"));
message.setRecipients(Message.RecipientType.TO, InternetAddress.parse("recipient@example.com"));
message.setSubject("Hello, World!");
message.setText("This is the message content.");
Transport.send(message);