1 package org.paneris.jammyjoes.controller; 2 3 import java.io.File; 4 import java.io.FileWriter; 5 import java.io.Writer; 6 import java.util.Enumeration; 7 8 import org.melati.Melati; 9 import org.melati.servlet.Form; 10 import org.melati.template.ServletTemplateContext; 11 import org.melati.util.Email; 12 import org.paneris.jammyjoes.mail.MailFascade; 13 import org.paneris.jammyjoes.mail.WriterFascade; 14 import org.paneris.jammyjoes.model.JammyjoesDatabase; 15 import org.paneris.jammyjoes.servlet.JammyJoesMelatiServlet; 16 import org.webmacro.servlet.WebContext; 17 18 public class NewsletterSend extends JammyJoesMelatiServlet { 19 20 private static final long serialVersionUID = 1L; 21 22 protected String jammyjoesRequest(Melati melati, ServletTemplateContext context) 23 throws Exception { 24 25 JammyjoesDatabase db = (JammyjoesDatabase) melati.getDatabase(); 26 String smtpserver = db.getSettingTable().get(Email.SMTPSERVER); 27 28 String newsletterDir = db.getSettingTable().get("UploadDir") + "/../"; 29 MailFascade facade = new MailFascade(smtpserver); 30 31 String start = Form.getFormNulled(context,"start"); 32 String end = Form.getFormNulled(context,"end"); 33 WebContext webContext = (WebContext)context.getContext(); 34 35 webContext.getResponse().setContentType("text/html"); 36 Enumeration users = db.getUserTable().selection("id >=" + start + " and id <=" + end, "id", true); 37 Writer out1 = melati.getWriter(); 38 Writer out2 = new FileWriter(new File(newsletterDir, "newsletter.log"),true); 39 out1.write("<h3>Sending email to everyone with an Id between " + start + " and " + end + ":</h3><br>"); 40 int count = facade.mailPeople(users, new WriterFascade(out1, out2), facade.createNewsletter(newsletterDir, "newsletter.html")); 41 webContext.put("number",count); 42 return "view/NewsletterSend.wm"; 43 } 44 45 }