use of org.tinystruct.mail.SimpleMail in project bible-online by m0ver.
the class password method send.
public boolean send(String mailto) throws ApplicationException {
User user = new User();
Table table = user.findWith("WHERE email=?", new Object[] { mailto });
if (table.size() > 0) {
org.tinystruct.data.component.Row row = table.get(0);
try {
SimpleMail themail = new SimpleMail();
themail.setFrom(this.getProperty("mail.default.from"));
themail.setSubject("密码重置邮件");
themail.setBody("亲爱的" + row.getFieldInfo("username").stringValue() + "用户,我们刚刚收到您的密码找回请求。为了保证您能及时使用我们提供的服务,请您于24小时内点击此链接重置您的密码。");
themail.setTo(mailto);
return themail.send();
} catch (Exception ex) {
throw new ApplicationException(ex.getMessage(), ex.getCause());
}
}
return false;
}
use of org.tinystruct.mail.SimpleMail in project bible-online by m0ver.
the class sender method invite.
public String invite() throws ApplicationException {
this.request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
HttpSession session = request.getSession();
if (session.getAttribute("usr") != null) {
this.user = (User) session.getAttribute("usr");
} else
return "false";
String mailto = "moverinfo@gmail.com";
if (this.request.getParameter("mailto") == null || this.request.getParameter("mailto").trim().length() == 0) {
return "false";
} else
mailto = this.request.getParameter("mailto");
String[] addresses = mailto.split(";");
for (int i = 0; i < addresses.length; i++) if (addresses[i].indexOf('@') < 1 || addresses[i].indexOf('@') >= addresses[i].lastIndexOf('.') + 1) {
return "invalid";
}
SimpleMail mail = new SimpleMail();
mail.setFrom(this.getProperty("mail.default.from"));
ActivationKey key = new ActivationKey();
String randomKey = key.getRandomCode();
String body = String.format(this.getProperty("mail.invitation.content"), this.getProperty("application.title"), this.getLink("user/register") + "/" + randomKey);
mail.setSubject(this.getProperty("mail.invitation.title"));
mail.setBody(body);
mail.setTo(mailto);
if (!mail.send()) {
return "error";
}
return "true";
}
use of org.tinystruct.mail.SimpleMail in project bible-online by m0ver.
the class sender method send.
public boolean send() {
this.request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
if (this.request.getParameter("id") == null || this.request.getParameter("text") == null || this.request.getParameter("text").trim().length() == 0) {
return false;
}
report report = new report();
report.setBibleId(this.request.getParameter("id"));
report.setLanguageId(0);
report.setUserId("-");
report.setStatus(0);
report.setUpdatedContent(this.request.getParameter("text"));
report.setModifiedTime(new Date());
try {
report.append();
bible bible = new bible();
if (this.getLocale().toString().equalsIgnoreCase(Locale.US.toString())) {
bible.setTableName("NIV");
} else if (this.getLocale().toString().equalsIgnoreCase(Locale.UK.toString())) {
bible.setTableName("KJV");
} else {
bible.setTableName(this.getLocale().toString());
}
bible.setId(report.getBibleId());
bible.findOneById();
SimpleMail mail = new SimpleMail();
mail.setFrom(this.getProperty("mail.default.from").toString());
// 你好!有一个用户发来的经文更新请求!<br />原文是:%s,建议更新为:%s <br/> --- <br />请点击此链接进行确认!(或复制此地址到浏览器访问):<br /> %s <br /><br /> InGod.asia工作小组
String body = String.format(this.getProperty("mail.report.content"), bible.getContent(), report.getUpdatedContent(), this.context.getAttribute("HTTP_HOST") + "services/bible/update/" + report.getId());
mail.setSubject(this.getProperty("mail.report.title"));
mail.setBody(body);
mail.addTo("moverinfo@gmail.com");
mail.send();
} catch (ApplicationException e) {
// TODO Auto-generated catch block
return false;
}
return true;
}
use of org.tinystruct.mail.SimpleMail in project bible-online by m0ver.
the class suggest method post.
public Object post() throws ApplicationException {
this.request = (HttpServletRequest) this.context.getAttribute(HTTP_REQUEST);
suggestion suggestion = new suggestion();
if (this.request.getParameter("content") == null || this.request.getParameter("content").trim().length() <= 0) {
this.setVariable("error", "<div class=\"error\">" + this.getProperty("suggestion.content.invalid") + "</div>");
return this;
}
if (this.request.getParameter("iemail") == null || this.request.getParameter("iemail").trim().length() <= 0) {
this.setVariable("error", "<div class=\"error\">" + this.getProperty("suggestion.email.invalid") + "</div>");
return this;
}
String content = this.request.getParameter("content");
String email = this.request.getParameter("iemail");
suggestion.setContent(content);
suggestion.setEmail(email);
suggestion.setIP(this.request.getRemoteAddr());
suggestion.setPostDate(new Date());
suggestion.setTitle("Suggestion");
try {
suggestion.append();
SimpleMail mail = new SimpleMail();
mail.setFrom(this.getProperty("mail.default.from").toString());
// 你好!有一个用户发来的经文更新请求!<br />原文是:%s,建议更新为:%s <br/> --- <br />请点击此链接进行确认!(或复制此地址到浏览器访问):<br /> %s <br /><br /> InGod.asia工作小组
String body = String.format(this.getProperty("mail.suggestion.content"), email, content);
mail.setSubject(this.getProperty("mail.suggestion.title"));
mail.setBody(body);
mail.addTo("moverinfo@gmail.com");
mail.send();
this.setVariable("error", "<div class=\"info\">" + this.getProperty("suggestion.send.success") + "</div>");
} catch (ApplicationException e) {
logger.severe(e.getMessage());
this.setVariable("error", "<div class=\"error\">" + this.getProperty("suggestion.send.failure") + "</div>");
}
this.setVariable("action", String.valueOf(this.context.getAttribute("HTTP_HOST")) + this.context.getAttribute("REQUEST_ACTION").toString());
HttpSession session = request.getSession();
if (session.getAttribute("usr") != null) {
this.usr = (User) session.getAttribute("usr");
this.setVariable("user.status", "");
this.setVariable("user.profile", "<a href=\"javascript:void(0)\" onmousedown=\"profileMenu.show(event,'1')\">" + this.usr.getEmail() + "</a>");
} else {
this.setVariable("user.status", "<a href=\"" + this.getLink("user/login") + "\">" + this.getProperty("page.login.caption") + "</a>");
this.setVariable("user.profile", "");
}
return this;
}
use of org.tinystruct.mail.SimpleMail in project bible-online by m0ver.
the class dailymail method start.
public boolean start() {
TimeIterator iterator = new TimeIterator(00, 00, 00);
iterator.setInterval(3600 * 24);
this.config.set("default.base_url", "http://www.ingod.today/?q=");
this.scheduler.schedule(new SchedulerTask() {
private Object o = new Object();
private boolean next = false;
@Override
public void cancel() {
// TODO Auto-generated method stub
scheduler.cancel();
}
@Override
public void start() {
synchronized (o) {
try {
SimpleMail themail = new SimpleMail();
themail.setFrom("国际圣经在线");
SimpleDateFormat format = new SimpleDateFormat("MM-dd");
plan plan = new plan();
Date date = new Date();
plan.findOneByKey("date", "2010-" + format.format(date).toString());
if (plan.getTask() == null) {
throw new ApplicationException("Task is not ready!");
}
// start
TaskDescriptor task = new TaskDescriptor();
bible bible = new bible();
if (locale.toString().equalsIgnoreCase(Locale.US.toString()))
bible.setTableName("NIV");
else
bible.setTableName("zh_CN");
StringBuffer where = task.parse(plan.getTask());
Table list = bible.findWith("WHERE " + where, new Object[] {});
Iterator<Row> iterators = list.iterator();
ArrayList<List<bible>> res = new ArrayList<List<bible>>();
List<bible> bibles = new ArrayList<bible>();
int bookId = 0, chapterId = 0;
while (iterators.hasNext()) {
bible bib = new bible();
bib.setData(iterators.next());
if (bookId != bib.getBookId()) {
bookId = bib.getBookId();
if (bibles.size() > 0)
res.add(bibles);
bibles = new ArrayList<bible>();
}
bibles.add(bib);
}
if (bibles.size() > 0)
res.add(bibles);
StringBuffer buffer = new StringBuffer();
buffer.append("<div style=\"background: none repeat scroll 0 0 -moz-field; border: 1px solid threedshadow; margin: 2em auto; padding: 2em;\">");
buffer.append(" <div>");
buffer.append(" <a style=\"-moz-margin-end: 0; -moz-margin-start: 0.6em; float: right; margin-bottom: 0; margin-top: 0;\">");
buffer.append(" <img id=\"feedTitleImage\" src=\"http://www.ingod.today/themes/images/favicon-b.png\"/> </a>");
buffer.append(" <div style=\"-moz-margin-end: 0.6em; -moz-margin-start: 0; margin-bottom: 0; margin-top: 0;\">");
buffer.append(" <h1 style=\"border-bottom: 2px solid threedlightshadow; font-size: 160%; margin: 0 0 0.2em;\">国际圣经在线</h1>");
// buffer.append(" <h2 style=\"color: #C0C0C0; font-weight: normal; margin: 0 0 0.6em;\">国际圣经在线为立志跟随主耶稣基督的朋友提供圣经阅读、圣经收听、圣经检索、福音电影分享以及资源下载等服务</h2>");
buffer.append(" </div>");
buffer.append(" </div>");
buffer.append(" <div id=\"feedContent\">");
buffer.append(" <div class=\"entry\">");
buffer.append(" <h2>");
String date_string = new SimpleDateFormat("MM/dd").format(date);
buffer.append(" <a href=\"http://www.ingod.today/?lang=zh-CN&q=feed/" + date_string + "\">每日读经 " + date_string + "</a>");
buffer.append(" </h2>");
buffer.append(" <div base=\"http://www.ingod.today/?lang=zh-CN&q=feed\" class=\"feedEntryContent\">");
Iterator<List<bible>> iterator = res.iterator();
book book = new book();
while (iterator.hasNext()) {
List<bible> bs = iterator.next();
Table table = book.findWith("WHERE book_id=? and language=?", new Object[] { bs.get(0).getBookId(), locale.toString().equalsIgnoreCase(Locale.US.toString()) ? Locale.US.toString() : "zh_CN" });
if (table.size() > 0) {
Row row = table.get(0);
book.setData(row);
}
buffer.append("<h3><a href=\"" + mail.getLink("bible") + "/" + book.getBookId() + "\">" + book.getBookName() + "</a></h3>");
Iterator<bible> iter = bs.iterator();
chapterId = 0;
while (iter.hasNext()) {
bible bi = iter.next();
if (chapterId != bi.getChapterId()) {
buffer.append("<h4><a href=\"" + mail.getLink("bible") + "/" + book.getBookId() + "/" + bi.getChapterId() + "\">" + bi.getChapterId() + "章</a></h4>");
chapterId = bi.getChapterId();
}
buffer.append(" ").append(bi.getPartId()).append(" ").append(bi.getContent());
}
}
Element element = new Element();
buffer.append("<br /><a href=\"" + mail.getLink("bible") + "\" style=\"float:right\">" + mail.getProperty("subscribe.continue.caption") + "</a>");
buffer.append(" </div>");
buffer.append(" </div>");
buffer.append(" <div style=\"clear: both;\"></div>");
buffer.append(" </div>");
buffer.append("</div>");
Element container = (Element) element.clone();
container.setName("div");
container.setAttribute("style", "background-color:#f5f5f5;text-align:justify");
container.setData(buffer.toString());
themail.setSubject("每日读经[" + format.format(new Date()).toString() + "]");
Element footer = new Element("div");
subscription subscription = new subscription();
Table table = subscription.findWith("WHERE available = 1", new Object[] {});
Iterator<Row> iterator1 = table.iterator();
while (iterator1.hasNext()) {
subscription.setData(iterator1.next());
footer.setAttribute("style", "padding:10px;font-size:12px;color:#ccc;");
footer.setData("让我们一起来养成每天读经的好习惯...<br />如果您不能正常访问此站点(<a href=\"http://www.ingod.today\">http://www.ingod.today</a>),请尝试通过VPN或运行代理程序(Freegate7.01)后,再进行访问,给您带来不便请谅解!如果你不想收到此邮件,请点击<a href=\"http://www.ingod.today/?q=services/unsubscribe/" + subscription.getId() + "\">退订</a>。");
themail.setBody(container.toString() + footer.toString());
themail.setTo(subscription.getEmail());
try {
themail.send();
} catch (ApplicationException e) {
subscription.setAvailable(false);
subscription.update();
}
}
// themail.attachFile("E:\\常用应用软件\\网络代理\\freegate7.01.rar");
Thread.sleep(1);
} catch (ApplicationException e) {
suggestion = new suggestion();
suggestion.setEmail("services@ingod.asia");
suggestion.setIP("-");
suggestion.setPostDate(new Date());
suggestion.setStatus(false);
suggestion.setTitle(e.getMessage() != null ? e.getMessage() : "");
note(e, suggestion);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
suggestion = new suggestion();
suggestion.setEmail("services@ingod.asia");
suggestion.setIP("-");
suggestion.setPostDate(new Date());
suggestion.setStatus(false);
suggestion.setTitle(e.getMessage() != null ? e.getMessage() : "");
note(e, suggestion);
} finally {
this.next = true;
}
// System.out.println("\r\nstarted");
// System.out.println("\r\nend..." + dateFormat.format(new Date()));
}
}
@Override
public boolean next() {
// TODO Auto-generated method stub
synchronized (o) {
return this.next;
}
}
}, iterator);
return true;
}
Aggregations