我尝试使用FreeMarker(.ftl)模板发送电子邮件。我在VelM中已经完成了FreeMarker中我想要的一些例子:
#set ($from = $var.getClass().forName('javax.mail.internet.InternetAddress').newInstance())
#set ($VOID = $from.setAddress($emailAddress))
#set ($VOID = $from.setPersonal($fullName))
#set ($to = $var.getClass().forName('javax.mail.internet.InternetAddress').newInstance())
#set ($VOID = $to.setAddress("admin@gmail.com"))
#set ($mailMessage = $var.getClass().forName('com.test.mail.service.MailMessage').newInstance())
#set ($VOID = $mailMessage.setBody("Sample Text."))
#set ($VOID = $mailMessage.setHTMLFormat('true'))
#set ($VOID = $mailMessage.setFrom($from))
#set ($VOID = $mailMessage.setSubject("Sample Subject"))
#set ($VOID = $mailMessage.setTo($to))
#set ($mailService = $serviceLocator.findService('com.test.mail.service.MailService'))
#set ($VOID = $mailService.sendEmail($mailMessage))
我的主要问题是获取一个类的新实例(即javax.mail.internet.InternetAddress
)。有没有办法获得这个类的新实例,以便我可以使用它?如果没有,我如何独家从FreeMarker模板发送电子邮件,类似于Velocity模板的做法?