如何使用 grails 在邮件中发送 icalendar 邀请。有一个名为“ ic-alendar:0.4.0 ”的插件,但我找不到任何解决方案如何使用此插件使用 grails mail API发送邮件
感谢。
答案 0 :(得分:1)
您必须使用icalendar插件将日历邀请创建为字符串,将其转换为字节[]然后将其作为文件附加到邮件插件。
这是我用来生成附件作为byte []的方法(我对我的应用程序SquadPoint.com有一个游戏的概念,所以我将其传递给封装在邀请上设置相关数据):< / p>
import ch.silviowangler.groovy.util.builder.ICalendarBuilder
//...
/**
* Create a calendar event for sending with an email as a .ics attachment
* @param game
* @param timeZoneId
* @return
*/
byte[] calendarEventAsBytes(Game game, timeZoneId) {
def organiserName = getOrganiserName(game)
def organiserEmail = getOrganiserEmail(game)
def builder = new ICalendarBuilder()
builder.calendar {
events {
event( start: game.dateTime,
end: game.dateTime.plusHours(1),
summary: "Game ${game.venue ? 'at ' + game.venue : ''}",
timezone: timeZoneId) {
organizer(name: organiserName, email: organiserEmail)
}
}
}
builder.cal.toString().getBytes('UTF-8')
}
然后发送附件到电子邮件:
def sendOutTeams(Game game) {
// some set up..
sesMail {
to email
subject "${organiserName} has selected teams (via Squadpoint.com)"
html groovyPageRenderer.render(template: '/email-templates/canYouPlay', model: emailModel)
attach "game.ics", "text/calendar", calendarEventAsBytes(game, timeZoneId)
}
}
我使用AWS插件使用SES发送我的电子邮件(因此sesMail配置关闭),但应该与常规的Grails Mail插件非常相似,如:
sendMail {
multipart true
to email
subject "a subject"
body "test"
attach "game.ics", "text/calendar", calendarEventAsBytes(game, timeZoneId)
}