PK zPh?m{EO O build.xml
PK H@\$ $ manifestversion=1.0
frameworkVersions=1.2.3
PK ل?Y2O O README.md# Play postmark module
This is a [play](http://www.playframework.org/) module for integrating [Postmark](http://postmarkapp.com) to handle outgoing e-mail in
you play application.
## About Postmark
> Postmark enables web applications of any size to deliver and track transactional email
> reliably, with minimal setup time and zero maintenance. We're the experts at getting
> your emails to the inbox, so you don't have to be.
## Getting started
Please have a look at the [documentation](https://github.com/FrostDigital/play-postmark/blob/master/documentation/manual/home.textile).PK n?#C
C
% app/jobs/postmark/PostmarkSender.javapackage jobs.postmark;
import com.postmark.java.PostmarkClient;
import com.postmark.java.PostmarkException;
import com.postmark.java.PostmarkMessage;
import com.postmark.java.PostmarkResponse;
import com.postmark.java.PostmarkStatus;
import play.Logger;
import play.Play;
import play.i18n.Messages;
import play.jobs.Job;
import play.jobs.OnApplicationStart;
import play.modules.postmark.Postmark;
import play.test.Fixtures;
public class PostmarkSender extends Job {
/**
* Client that communicates with Postmark's REST API.
*/
private static PostmarkClient postmarkClient;
/**
* The message *this* sender will send
*/
private PostmarkMessage message;
/**
* Private, use {@link #sendMail(...)} instead!
* @param message
*/
private PostmarkSender(PostmarkMessage message) {
this.message = message;
}
public void doJob() {
try {
if(Postmark.ctx.isTest()) {
logMessage(message);
}
PostmarkResponse resp = postmarkClient.sendMessage(message);
if(Postmark.ctx.isTest() || !PostmarkStatus.SUCCESS.equals(resp.getStatus()) ) {
logResponse(resp);
}
} catch (PostmarkException e) {
Logger.warn("Could not send mail to '%s':", message.getToAddress(), e.getMessage());
}
}
/**
* Send mail given recipient from given sender.
* @param from - sender, must be a valid "sender signature" registered @ postmarkapp.com
* @param to
* @param subject
* @param body - message content
*/
public static void sendMail(String from, String to, String subject, String body) {
if(from == null && Postmark.ctx.getDefaultFrom() != null) {
from = Postmark.ctx.getDefaultFrom();
}
sendMail(new PostmarkMessage(from, to, null, null, subject, body, false, null));
}
/**
* Send mail to given recipient.
* @param to
* @param subject
* @param body - message content
*/
public static void sendMail(String to, String subject, String body) {
sendMail(null, to, subject, body);
}
/**
* Creates a new AsyncMailJob and runs it.
* @param message
* @param isTest
*/
public static void sendMail(PostmarkMessage message) {
assert Postmark.ctx != null : "Postmark module has not been initialized";
assert message.getFromAddress() != null : "Cannot send mail, 'from' is null";
if(postmarkClient == null) {
postmarkClient = new PostmarkClient(Postmark.ctx.getApiKey());
}
new PostmarkSender(message).doJob();
}
private static void logMessage(PostmarkMessage message) {
Logger.info(
new StringBuilder()
.append("\n------- Postmark will send message ------")
.append("\nTo: ").append(message.getToAddress())
.append("\nFrom: ").append(message.getFromAddress())
.append("\nSubject: ").append(message.getSubject())
.append("\nBody:\n").append( message.getTextBody() == null ? message.getHtmlBody() : message.getTextBody() )
.toString()
);
}
private static void logResponse(PostmarkResponse resp) {
Logger.info(
new StringBuilder()
.append("\n------- Postmark response ------")
.append("\nStatus: ").append(resp.getStatus())
.append("\nStatus message: ").append(resp.getMessage())
.append("\nError code: ").append(resp.getErrorCode())
.append("\nTo: ").append(resp.getTo())
.toString()
);
}
}
PK H@1h h conf/dependencies.ymlself: play -> postmark 1.0
require:
- play
- org.apache.httpcomponents -> httpclient 4.0.1
PK ̩?(p ! documentation/manual/home.textileh1. Postmark module
Postmark module enables easy integration with "postmarkapp.com":http://postmarkapp.com for handling outgoing emails.
Sending emails can be a hassle. You need to follow best practice in order to avoid spam filters and it is hard to create you own system that track delivery status etc.
Here is how they describe it (from their landing page):
bq. Postmark enables web applications of any size to deliver and track transactional email reliably, with minimal setup time and zero maintenance. We're the experts at getting your emails to the inbox, so you don't have to be.
h2. Enable and configure the module
bq. NOTE: You need to create an account @ "postmarkapp.com":http://postmarkapp.com to be able to use this module. Read more about it "here":http://developer.postmarkapp.com/.
Add the following dependency to **/conf/dependencies.yml**:
bc. - play -> postmark 1.0
Now sync dependencies and module will be downloaded:
bc. play deps --sync
As of Play 1.2.4 you may add flag **--forProd** to exclude docs and sample app from module:
bc. play deps --sync --forProd
h3. Configuration
Add following properties to **/conf/application.conf**:
bc. # Enter you API-key from postmark here
postmark.apiKey=YOUR-API-KEY-HERE
# This email must be a valid "sender signature"
postmark.from=darth@space.com
If you don't want to run full integration, i.e. not sending actual emails just make sure that your data is valid, in dev/test mode you may utilize postmarks test key:
bc. postmark.apiKey=POSTMARK_API_TEST
%prod.postmark.apiKey=YOUR-API-KEY-HERE
# This email must be a valid "sender signature"
play.postmark.from=darth@space.com
The plugin will check if test key **POSTMARK_API_TEST** is used and log messages if that is the case.
h2. Usage
Use any of the PostmarkSender.sendMail(...) methods. This will create a new job and send mail async.
Example:
bc. PostmarkSender.sendMail("luke@space.com", "Important!", "Luke, I am your father. \n\nKindly, Darth");
PK ͂?p p lib/httpclient-4.0.1.jarPK
o; META-INF/PK
n;5 META-INF/MANIFEST.MFMn R$UTV]`lb@Ŏ&c͛
{nTC ([zѩ#8Oek<$wlSjhO$;2.sЃ 9^Ђ((q-?]OdSHe@vwޜK5-3)zpXwb)QPK
; org/PK
; org/apache/PK
; org/apache/http/PK
; org/apache/http/cookie/PK
; org/apache/http/cookie/params/PK
; org/apache/http/auth/PK
; org/apache/http/auth/params/PK
; org/apache/http/annotation/PK
; org/apache/http/client/PK
; org/apache/http/client/methods/PK
; org/apache/http/client/entity/PK
; org/apache/http/client/protocol/PK
; org/apache/http/client/params/PK
; org/apache/http/client/utils/PK
; org/apache/http/impl/PK
; org/apache/http/impl/cookie/PK
; org/apache/http/impl/auth/PK
; org/apache/http/impl/client/PK
; org/apache/http/impl/conn/PK
; org/apache/http/impl/conn/tsccm/PK
; org/apache/http/conn/PK
; org/apache/http/conn/ssl/PK
; org/apache/http/conn/routing/PK
; org/apache/http/conn/util/PK
; org/apache/http/conn/params/PK
; org/apache/http/conn/scheme/PK
;^Q j ' org/apache/http/cookie/CookieSpec.classRMO@}@E㦧rqƋ+p `a-kYm?8m
F^vͼ}7v-1