aipoでメールを送信するコマンド

aipoではメール送信をAmazon sesによって送信しています

それとVelocityをメールのテンプレートにする方法と合わせた以下のようなメソッドを用いて送信しています


public static boolean sendMail(String to, String type, Map<String, Object> maps) { try { VelocityContext context = new VelocityContext(); Iterator<Entry<String, Object>> iterator = maps.entrySet().iterator(); while (iterator.hasNext()) { Entry<String, Object> next = iterator.next(); context.put(next.getKey(), next.getValue()); } StringWriter writer = new StringWriter(); try { Properties p = new Properties(); p.setProperty("resource.loader", "class"); p .setProperty( "class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader"); p.setProperty("input.encoding", "UTF-8"); Velocity.init(p); Template template = Velocity.getTemplate(type + ".vm", "utf-8"); template.merge(context, writer); } catch (Exception e) { throw new WicketRuntimeException(e); } writer.flush(); String content = writer.getBuffer().toString(); String from = WebContextLocator.get().getProperty( AWSContext.get().appendConfigPrefix("mail.from")); String name = WebContextLocator.get().getProperty( AWSContext.get().appendConfigPrefix("mail.name")); String subject = WebContextLocator.get().getProperty( AWSContext.get().appendConfigPrefix("mail.subject." + type)); AmazonSimpleEmailService ses = SES.getClient(); JISMimeMessage message = new JISMimeMessage(); message.setFrom(name, from); message.setRecipients(RecipientType.TO, to); message.setSubject(subject); message.setTextContent(content); ses.sendRawEmail(new SendRawEmailRequest(message.getRawMessage())); return true; } catch (Throwable t) { logger.error("Error", t); } return false; }