标签:any spring str bsp https request rac trace print
private void sendMany(List<String> lstAddress, String mailFrom,String subject, String text,String API_KEY) {
try{
Email from = new Email(mailFrom);
Mail mail = new Mail();
for (String mailto : lstAddress) {
Email to = new Email(mailto);
Personalization personalization = new Personalization();
personalization.addTo(to);
personalization.addSubstitution("-name-", mailto);
mail.addPersonalization(personalization);
}
mail.setFrom(from);
mail.setSubject(subject);
Content content = new Content("text/plain", text);
mail.addContent(content);
SendGrid sg = new SendGrid(API_KEY);
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
}catch(IOException ex){
ex.printStackTrace();
}
}
mail.build()生成的JSON结构如下:
{ "to" : [ "alice@test.com", "bob@test.com" ], "sub": { "-name-": [ "アリス", "ボブ" ] }
标签:any spring str bsp https request rac trace print
原文地址:https://www.cnblogs.com/atq999/p/11942979.html