0
私はGroovyクラスで以下のコードを使用しています。このメソッドを他のさまざまなGroovyクラスから非同期的に呼び出す必要があります。groovyでの非同期電子メール通知
public void sendNotification(){
//async true
String from = ApplicationConfig.email_From;
String sendTo = ApplicationConfig.email_To;
String host = ApplicationConfig.email_Host;
String subject = ApplicationConfig.email_Subject;
String textToSend = ApplicationConfig.email_Text;
Properties properties = System.getProperties();
properties.setProperty("mail.smtp.host", host);
Session session = Session.getDefaultInstance(properties);
try{
MimeMessage message = new MimeMessage(session);
message.setFrom(new InternetAddress(from));
message.addRecipients(Message.RecipientType.TO, InternetAddress.parse(sendTo));
message.setSubject(subject);
message.setText(textToSend);
Transport.send(message);
}catch (MessagingException mex) {
mex.printStackTrace();
}
}
は、これまでのところ私は、Grailsの中にいくつかのプラグインがありますが、私の要件に合ったものを見つけることができませんでしたが、私はGrailsのを使用していませんよ。