Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade play-mailer and use new play-mailer repo #32

Merged
merged 1 commit into from
May 24, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions code/app/com/feth/play/module/mail/Mailer.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import akka.actor.Cancellable;
import com.feth.play.module.mail.Mailer.Mail.Body;
import com.typesafe.plugin.MailerAPI;
import com.typesafe.plugin.MailerPlugin;
import play.libs.mailer.Email;
import play.libs.mailer.MailerPlugin;
import play.Configuration;
import play.libs.Akka;
import scala.concurrent.duration.Duration;
Expand All @@ -29,8 +29,6 @@ public static class SettingKeys {
private static final String VERSION = "version";
}

private final MailerPlugin plugin;

private final FiniteDuration delay;

private final String sender;
Expand Down Expand Up @@ -80,7 +78,6 @@ public static String getEmailName(final String email, final String name) {
}

protected Mailer(final Configuration config) {
plugin = play.Play.application().plugin(MailerPlugin.class);
delay = Duration.create(config.getLong(SettingKeys.DELAY, 1L), TimeUnit.SECONDS);

final Configuration fromConfig = config.getConfig(SettingKeys.FROM);
Expand Down Expand Up @@ -385,49 +382,51 @@ public MailJob(final Mail m) {

@Override
public void run() {
final MailerAPI api = plugin.email();
final Email email = new Email();

api.setSubject(mail.getSubject());
api.setRecipient(mail.getRecipients());
email.setSubject(mail.getSubject());
email.setTo(Arrays.asList(mail.getRecipients()));
if (mail.getCc() != null) {
api.setCc(mail.getCc());
email.setCc(Arrays.asList(mail.getCc()));
}
if (mail.getBcc() != null) {
api.setBcc(mail.getBcc());
email.setBcc(Arrays.asList(mail.getBcc()));
}
api.setFrom(mail.getFrom());
email.setFrom(mail.getFrom());
if (includeXMailerHeader) {
api.addHeader("X-Mailer", MAILER + getVersion());
email.addHeader("X-Mailer", MAILER + getVersion());
}

for (final Entry<String, List<String>> entry : mail
.getCustomHeaders().entrySet()) {
final String headerName = entry.getKey();
for (final String headerValue : entry.getValue()) {
api.addHeader(headerName, headerValue);
email.addHeader(headerName, headerValue);
}
}
if (mail.getReplyTo() != null) {
api.setReplyTo(mail.getReplyTo());
email.setReplyTo(mail.getReplyTo());
}
for (final Mail.Attachment attachment : mail.getAttachments()) {
if (attachment.getData() != null) {
api.addAttachment(attachment.getName(), attachment.getData(), attachment.getMimeType(), attachment.getDescription(), attachment.getDisposition());
email.addAttachment(attachment.getName(), attachment.getData(), attachment.getMimeType(), attachment.getDescription(), attachment.getDisposition());
} else {
api.addAttachment(attachment.getName(), attachment.getFile(), attachment.getDescription(), attachment.getDisposition());
email.addAttachment(attachment.getName(), attachment.getFile(), attachment.getDescription(), attachment.getDisposition());
}
}
if (mail.getBody().isBoth()) {
// sends both text and html
api.send(mail.getBody().getText(), mail.getBody().getHtml());
email.setBodyText(mail.getBody().getText());
email.setBodyHtml(mail.getBody().getHtml());
} else if (mail.getBody().isText()) {
// sends text/text
api.send(mail.getBody().getText());
email.setBodyText(mail.getBody().getText());
} else {
// if(mail.isHtml())
// sends html
api.sendHtml(mail.getBody().getHtml());
email.setBodyHtml(mail.getBody().getHtml());
}
MailerPlugin.send(email);
}

}
Expand Down
2 changes: 1 addition & 1 deletion code/build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ scalaVersion := "2.11.2"
crossScalaVersions := Seq("2.10.4", "2.11.2")

libraryDependencies ++= Seq(
"com.typesafe.play.plugins" %% "play-plugins-mailer" % "2.3.1"
"com.typesafe.play" %% "play-mailer" % "2.4.1"
)

lazy val root = (project in file(".")).enablePlugins(PlayJava)
2 changes: 1 addition & 1 deletion code/conf/play.plugins
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1500:com.typesafe.plugin.CommonsMailerPlugin
1500:play.api.libs.mailer.CommonsMailerPlugin