برای این کار می توانید از کتابخانه JavaMail API استفاده کنید:
Properties props = new Properties();
props.put("mail.smtp.host", "mail.javabyab.com");
props.put("mail.smtp.port", "25");
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("noreply@javabyab.com"));
message.setRecipients(Message.RecipientType.TO,
InternetAddress.parse("to-email@gmail.com"));
message.setSubject("subject");
message.setText("email text");
Transport.send(message);
} catch (MessagingException e) {
throw new RuntimeException(e);
}