import java.util.Properties;
import javax.mail.*;
import javax.mail.internet.*;
public class MassEmailSender {
public static void main(String[] args) {
// Sender's information
String fromEmail = "your_email@gmail.com";
String password = "your_password";
// SMTP server information
String smtpHost = "smtp.gmail.com";
int smtpPort = 587;
// Recipient information
String[] toEmails = {"recipient1@example.com", "recipient2@example.com"};
// Set JavaMail properties
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", smtpPort);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
// Create a Session object
Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(fromEmail, password);
}
});
try {
// Create a MimeMessage object
Message message = new MimeMessage(session);
// Set the sender
message.setFrom(new InternetAddress(fromEmail));
// Set the recipients
for (String toEmail : toEmails) {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));
}
// Set the email subject
message.setSubject("Mass Email Test");
// Set the email content
message.setText("This is a test email for mass mailing.");
// Send the email
Transport.send(message);
System.out.println("Email sent successfully");
} catch (MessagingException e) {
System.err.println("Email sending failed: " + e.getMessage());
}
}
}
import javax.mail.*;
import javax.mail.internet.*;
public class MassEmailSender {
public static void main(String[] args) {
// Sender's information
String fromEmail = "your_email@gmail.com";
String password = "your_password";
// SMTP server information
String smtpHost = "smtp.gmail.com";
int smtpPort = 587;
// Recipient information
String[] toEmails = {"recipient1@example.com", "recipient2@example.com"};
// Set JavaMail properties
Properties props = new Properties();
props.put("mail.smtp.host", smtpHost);
props.put("mail.smtp.port", smtpPort);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.starttls.enable", "true");
// Create a Session object
Session session = Session.getInstance(props, new Authenticator() {
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(fromEmail, password);
}
});
try {
// Create a MimeMessage object
Message message = new MimeMessage(session);
// Set the sender
message.setFrom(new InternetAddress(fromEmail));
// Set the recipients
for (String toEmail : toEmails) {
message.addRecipient(Message.RecipientType.TO, new InternetAddress(toEmail));
}
// Set the email subject
message.setSubject("Mass Email Test");
// Set the email content
message.setText("This is a test email for mass mailing.");
// Send the email
Transport.send(message);
System.out.println("Email sent successfully");
} catch (MessagingException e) {
System.err.println("Email sending failed: " + e.getMessage());
}
}
}