import javax.mail.*;
import javax.mail.internet.*;
public class SendEmail {
public static void main(String[] args) {
String to = "recipient@example.com";
String from = "sender@example.com";
String host = "smtp.example.com";
String username = "your-username";
String password = "your-password";
java.util.Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
properties.setProperty("mail.user", username);
properties.setProperty("mail.password", password);
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("Hello, JavaMail API!");
message.setText("This is a test email from JavaMail API.");
Transport.send(message);
System.out.println("Email sent successfully.");
} catch (MessagingException ex) {
ex.printStackTrace();
}
}
}