| 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 | 0 | 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 | 0 | JammyjoesDatabase db = (JammyjoesDatabase) melati.getDatabase(); |
| 26 | 0 | String smtpserver = db.getSettingTable().get(Email.SMTPSERVER); |
| 27 | |
|
| 28 | 0 | String newsletterDir = db.getSettingTable().get("UploadDir") + "/../"; |
| 29 | 0 | MailFascade facade = new MailFascade(smtpserver); |
| 30 | |
|
| 31 | 0 | String start = Form.getFormNulled(context,"start"); |
| 32 | 0 | String end = Form.getFormNulled(context,"end"); |
| 33 | 0 | WebContext webContext = (WebContext)context.getContext(); |
| 34 | |
|
| 35 | 0 | webContext.getResponse().setContentType("text/html"); |
| 36 | 0 | Enumeration users = db.getUserTable().selection("id >=" + start + " and id <=" + end, "id", true); |
| 37 | 0 | Writer out1 = melati.getWriter(); |
| 38 | 0 | Writer out2 = new FileWriter(new File(newsletterDir, "newsletter.log"),true); |
| 39 | 0 | out1.write("<h3>Sending email to everyone with an Id between " + start + " and " + end + ":</h3><br>"); |
| 40 | 0 | int count = facade.mailPeople(users, new WriterFascade(out1, out2), facade.createNewsletter(newsletterDir, "newsletter.html")); |
| 41 | 0 | webContext.put("number",count); |
| 42 | 0 | return "view/NewsletterSend.wm"; |
| 43 | |
} |
| 44 | |
|
| 45 | |
} |