grails - 如何发送多个HTML电子邮件到Grails中的用户列表或用户数组(带有电子邮件)?

标签 grails html-email gsp

我有一个用户域,我想一次向所有用户发送电子邮件。
但是我可以单独发送电子邮件,但不确定如何处理发送的多个电子邮件。
我的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上使用它来使其工作。
我需要知道将什么变量或数组传递给电子邮件服务以及如何传递。

最佳答案

哇,这看起来像很多额外的工作。使用mail pluginDocs显示如何发送给多个收件人。

sendMail {
    to "someoneorg.com", "someone.elseorg.com"
    …
}

关于grails - 如何发送多个HTML电子邮件到Grails中的用户列表或用户数组(带有电子邮件)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18392202/

相关文章:

html - GSP/JSP for循环-第一个节点 'selected'类

grails - 将Grails应用程序部署到负载均衡器后面的2台服务器-Spring Security clearCachedRequestmaps()

grails - 想法 : Grails SDK is not selected

html - 如何使用@Media 查询

html - 电子邮件的可滚动表格(没有 div)

grails - Grails-检查项目是否具有父项

grails:脚手架为具有 hasMany 关系的域创建 View

grails - 将数据从 Controller 传递到过滤器

grails - Camel 案的包裹涉及多个有意义的步骤

html - 您应该为 HTML 电子邮件通讯使用的最大宽度是多少?