我尝试发送多封使用HTML进行格式化的电子邮件,但只有第一封电子邮件以HTML格式发送,其余电子邮件以纯文本形式发送。
任何人都知道问题可能是什么?
这是我发送多封电子邮件的代码:
public static int sendEmail(int ind) throws AddressException, MessagingException, InterruptedException, IOException {
mailServerProperties = System.getProperties();
mailServerProperties.put("mail.smtp.port", "587");
mailServerProperties.put("mail.smtp.auth", "true");
mailServerProperties.put("mail.smtp.starttls.enable", "true");
getMailSession = Session.getDefaultInstance(mailServerProperties, null);
generateMailMessage = new MimeMessage(getMailSession);
generateMailMessage.setSubject("Greetings");
Transport transport = getMailSession.getTransport("smtp");
transport.connect("smtp.gmail.com", email, password);
Person perp;
for(int i = ind; i < people.size(); i++){
perp = people.get(i);
generateMailMessage.setRecipient(Message.RecipientType.TO, new InternetAddress(perp.email));
emailBody = "Dear " + perp.name + ", <br><br> Testing. <br><br>The Tester";
generateMailMessage.setContent(emailBody, "text/html; charset=utf-8");
generateMailMessage.setSubject("Greetings"+i);
try{
transport.sendMessage(generateMailMessage, generateMailMessage.getAllRecipients());
System.out.println(i);
} catch(Exception SMTPSendFailedException) {
System.out.println("Number "+i+" failed");
ind = i;
break;
}
ind = i;
}
System.out.println("round done");
transport.close();
return ind;
}