Skip to content

Commit

Permalink
Add convenience methods to MailGun class
Browse files Browse the repository at this point in the history
  • Loading branch information
jpasqua committed Nov 27, 2014
1 parent aba364e commit 4806d38
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/org/noroomattheinn/utils/MailGun.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
package org.noroomattheinn.utils;

import java.io.IOException;
import org.apache.commons.lang3.StringUtils;
import org.noroomattheinn.tesla.Tesla;
import static org.noroomattheinn.tesla.Tesla.logger;
import us.monoid.web.FormContent;
import us.monoid.web.TextResource;

Expand All @@ -26,7 +28,25 @@ public MailGun(String user, String auth) {
setAuthHeader(api, user, auth);
}

public boolean send(String to, String message) {
final int SubjectLength = 30;
String subject = StringUtils.left(message, SubjectLength);
if (message.length() > SubjectLength) {
subject = subject + "...";
}
return send(to, subject, message);
}

public boolean send(String to, String subject, String message) {
if (subject == null) subject = "";
if ((message == null || message.isEmpty()) && subject.isEmpty()) {
logger.warning("No message or subject specified, message not sent");
return false;
}
if (to == null || to.isEmpty()) {
logger.warning("No recipient specified, message not sent: " + message);
return false;
}
to = to.replaceAll("\\s+", ""); // In case there is a comma-separated list of addresses
FormContent fc = RestyWrapper.form(
"[email protected]" +
Expand Down

0 comments on commit 4806d38

Please sign in to comment.