package com.ruzhoukj.sms.task; import java.util.Properties; import javax.mail.Message; import javax.mail.MessagingException; import javax.mail.Session; import javax.mail.Transport; import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage; public class SendEmailExample { public static void main(String[] args) { final String username = "2404263178@qq.com"; final String password = "eryzvsveckiudiee"; // QQ Mail SMTP server information Properties props = new Properties(); props.put("mail.smtp.auth", "true"); props.put("mail.smtp.starttls.enable", "true"); props.put("mail.smtp.host", "smtp.qq.com"); props.put("mail.smtp.port", "587"); Session session = Session.getInstance(props, new javax.mail.Authenticator() { @Override protected javax.mail.PasswordAuthentication getPasswordAuthentication() { return new javax.mail.PasswordAuthentication(username, password); } }); try { Message message = new MimeMessage(session); message.setFrom(new InternetAddress(username)); // 添加多个收件人 String[] toAddresses = {"2404263178@qq.com","zhuxiang@ruzhoukj.com"}; message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(String.join(", ", toAddresses))); message.setSubject("ssl证书即将到期"); message.setText("This is the message body"); Transport.send(message); System.out.println("Email sent successfully to multiple recipients."); } catch (MessagingException e) { throw new RuntimeException(e); } } }