add mail test

master
wangning 7 years ago
parent ec0ead8d68
commit dc1f20c838

@ -3,15 +3,33 @@ package au.com.royalpay.payment.manage.apps.core.impls;
import au.com.royalpay.payment.manage.mappers.payment.OrderMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.manage.mappers.system.OrgMapper;
import au.com.royalpay.payment.tools.mail.MailGunClient;
import au.com.royalpay.payment.tools.mail.SendMail;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang3.time.DateUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.bind.annotation.RequestMethod;
import java.io.IOException;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;
import javax.annotation.Resource;
import cn.yixblog.platform.http.HttpRequestGenerator;
import cn.yixblog.platform.http.HttpRequestResult;
/**
* Created by wangning on 05/01/2018.
*/
@ -28,6 +46,8 @@ public class CustomerImpressionImplTest {
private ClientMapper clientMapper;
@Resource
private OrgMapper orgMapper;
@Resource
private MailGunClient mailGunClient;
// @Test
// public void redisQueue() {
@ -73,4 +93,54 @@ public class CustomerImpressionImplTest {
// }
// }
@Test
public void sendSimpleMessage() throws Exception {
String url = "https://api.mailgun.net/v3/dev.showcodes.com/events";
HttpRequestGenerator generator = new HttpRequestGenerator(url, RequestMethod.POST).addHeader("Authorization", getHeader());
generator.addQueryString("ascending", "yes");
generator.addQueryString("limit", "12");
System.out.println(String.valueOf(DateUtils.addDays(new Date(),1)));
HttpRequestResult res = null;
try {
res = generator.execute();
} catch (URISyntaxException e) {
e.printStackTrace();
}
System.out.println(res.getException());
System.out.println();
System.out.println();
try {
System.out.println(res.getResponseContentJSONObj().toJSONString());
} catch (IOException e) {
e.printStackTrace();
}
}
private String getHeader() {
String auth = "api:key-96fa3b5866ace125b8ec5a9d27e19353";
byte[] encodedAuth = Base64.encodeBase64(auth.getBytes(Charset.forName("UTF-8")));
String authHeader = "Basic " + new String(encodedAuth);
return authHeader;
}
@Test
public void sendSimpleMessages() throws Exception {
SendMail sendMail = new SendMail();
sendMail.setContent("<html><p>Hi kira</p ></html>");
Set<String> mailCCs = new HashSet<>();
mailCCs.add("164851225@qq.com");
sendMail.setMailCcs(mailCCs);
Set<String> mailtos = new HashSet<>();
mailtos.add("1029811920@qq.com");
sendMail.setMailTos(mailtos);
sendMail.setTitle("Final Test");
JSONObject result = mailGunClient.sendMail(sendMail);
System.out.println(result.toJSONString());
System.out.println(result.toJSONString());
System.out.println(result.toJSONString());
}
}
Loading…
Cancel
Save