Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Implement simple mail sending

  • Loading branch information...
commit 43dc318a33203a7ae395d80f44e1768f0ce21bcf 1 parent 9ab0cc5
k-shunji authored
View
2  LICENSE.txt
@@ -1,4 +1,4 @@
-Copyright (c) 2013 Shunji Konishi and FLECT CO.,LTD.
+Copyright (c) 2013 Shunji Konishi(FLECT CO.,LTD.)
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
View
2  README.md
@@ -4,7 +4,7 @@ sendgrid4j
Overview
--------
-Simple java client for SendGrid
+Simple SendGrid client for Java
License
-------
View
4 src/main/java/jp/co/flect/sendgrid/SendGridClient.java
@@ -137,7 +137,9 @@ public void deleteInvalidEmails(InvalidEmail.Delete request) {
}
//Mail
- public void mail(WebMail mail, File... attachements) {
+ public void mail(WebMail mail, File... attachements) throws IOException, SendGridException {
+ String json = doRequest("/mail.send.json", mail);
+System.out.println("mail send: " + json);
}
//Multiple Credentials - NOT IMPLEMENTED
View
43 src/main/java/jp/co/flect/sendgrid/model/WebMail.java
@@ -1,4 +1,45 @@
package jp.co.flect.sendgrid.model;
-public class WebMail {
+import java.util.List;
+
+public class WebMail extends AbstractRequest {
+
+ public String getTo() { return doGetString("to");}
+ public void setTo(String s) { doSetString("to", s);}
+
+ public List getToList() { return doGetList("to");}
+ public void setToList(List<String> list) { doSetList("to", list);}
+
+ public String getToName() { return doGetString("toname");}
+ public void setToName(String s) { doSetString("toname", s);}
+
+ public List getToNameList() { return doGetList("toname");}
+ public void setToNameList(List<String> list) { doSetList("toname", list);}
+
+ public String getFrom() { return doGetString("from");}
+ public void setFrom(String s) { doSetString("from", s);}
+
+ public String getFromName() { return doGetString("fromname");}
+ public void setFromName(String s) { doSetString("fromname", s);}
+
+ public String getSubject() { return doGetString("subject");}
+ public void setSubject(String s) { doSetString("subject", s);}
+
+ public String getText() { return doGetString("text");}
+ public void setText(String s) { doSetString("text", s);}
+
+ public String getHtml() { return doGetString("html");}
+ public void setHtml(String s) { doSetString("html", s);}
+/*
+x-smtpapi
+subject
+text
+html
+bcc
+replyto
+date
+files
+content
+headers
+*/
}
View
4 src/test/java/jp/co/flect/sendgrid/JsonTest.java
@@ -39,6 +39,10 @@ public void parse() throws Exception {
test(map, "array2", Arrays.asList(1.0, 2.0, 3.0));
test(map, "array3", Arrays.asList(true, false, true));
test(map, "array4", Arrays.asList("str1", 2.0, true));
+
+ String str2 = JsonUtils.serialize(map);
+ System.out.println("Serialize: " + str2);
+ assertEquals(map, JsonUtils.parse(str2));
}
private void test(Map<String, Object> map, String key, Object expected) {
View
27 src/test/java/jp/co/flect/sendgrid/SendGridTest.java
@@ -12,14 +12,20 @@
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;
+import java.util.Arrays;
import java.util.List;
+import java.util.Date;
import jp.co.flect.sendgrid.model.InvalidEmail;
+import jp.co.flect.sendgrid.model.WebMail;
public class SendGridTest {
private static String USERNAME;
private static String PASSWORD;
+ private static String MAIL_FROM;
+ private static String MAIL_TO;
+
@BeforeClass
public static void setup() throws Exception {
Properties props = new Properties();
@@ -30,11 +36,15 @@ public static void setup() throws Exception {
} finally {
is.close();
}
- USERNAME = props.getProperty("SENDGRID_USERNAME");
- PASSWORD = props.getProperty("SENDGRID_PASSWORD");
+ USERNAME = props.getProperty("SENDGRID_USERNAME");
+ PASSWORD = props.getProperty("SENDGRID_PASSWORD");
+ MAIL_FROM = props.getProperty("MAIL_FROM");
+ MAIL_TO = props.getProperty("MAIL_TO");
assertNotNull(USERNAME);
assertNotNull(PASSWORD);
+ assertNotNull(MAIL_FROM);
+ assertNotNull(MAIL_TO);
}
@Test
@@ -62,4 +72,17 @@ public void limitError() throws Exception {
assertTrue(e.getMessage().indexOf("Limit") > 0);
}
}
+
+ @Test
+ public void sendMail() throws Exception {
+ SendGridClient client = new SendGridClient(USERNAME, PASSWORD);
+ WebMail mail = new WebMail();
+ mail.setFrom(MAIL_FROM);
+// mail.setTo(MAIL_TO);
+ mail.setToList(Arrays.asList("k-shunji@flect.co.jp", "shun.konishi@nifty.com"));
+ mail.setSubject("テストメール: " + new Date());
+ mail.setText("てすと\nてすと");
+
+ client.mail(mail);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.