我有一个用户域,我想一次性向所有用户发送一封电子邮件。但是我可以单独发送电子邮件,但不确定如何处理发送的多封电子邮件。我的 emailService 如下所示:
def mailSender
def mailMessage // a "prototype" email instance
ApplicationContext applicationContext
/**
* Send a list of emails.
*
* @param mails a list of maps
*/
boolean sendEmails(mails) {
def retval = true
// Build the mail messages
def messages = []
for (mail in mails) {
// create a copy of the default message
MimeMessage mimeMessage = mailSender.createMimeMessage()
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage, true, "ISO-8859-1");
helper.setFrom(mail.from);
helper.setTo(getInternetAddresses(mail.to));
helper.setSubject(mail.subject);
helper.setText(mail.text, true);
if(mail.bcc)
helper.setBcc(getInternetAddresses(mail.bcc));
if(mail.cc)
helper.setCc(getInternetAddresses(mail.cc));
messages << mimeMessage
}
// Send them all together
try {
log.debug("mailsender")
mailSender.send(messages as MimeMessage[])
}
catch (MailException e) {
log.error "Failed to send emails: $e.message", e
retval = false
}
catch (MessagingException e) {
log.error "Failed to send emails: $e.message", e
retval = false
}
return retval
}
我不知道如何在 gsp 上使用它来使其工作。我需要知道我需要将哪些变量或数组传递给电子邮件服务以及如何传递。