import javax.mail.*;
import javax.mail.internet.*;
import java.util.Properties;
public class EmailSender {
public static void main(String[] args) {
String to = "recipient@example.com";
String from = "sender@example.com";
String host = "localhost";
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try {
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipient(Message.RecipientType.TO, new InternetAddress(to));
message.setSubject("This is the subject of the email");
message.setText("This is the body of the email");
Transport.send(message);
System.out.println("Email sent successfully.");
} catch (MessagingException mex) {
mex.printStackTrace();
}
}
}