在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:sendgrid/sendgrid-java开源软件地址:https://github.com/sendgrid/sendgrid-java开源编程语言:Java 99.3%开源软件介绍:This library allows you to quickly and easily use the Twilio SendGrid Web API v3 via Java. Version 3.X.X of this library provides full support for all Twilio SendGrid Web API v3 endpoints, including the new v3 /mail/send. This library represents the beginning of a new path for Twilio SendGrid. We want this library to be community driven and Twilio SendGrid led. We need your help to realize this goal. To help make sure we are building the right things in the right order, we ask that you create issues and pull requests or simply upvote or comment on existing issues or pull requests. If you need help using SendGrid, please check the Twilio SendGrid Support Help Center. Table of Contents
InstallationPrerequisites
Setup Environment VariablesUpdate the development environment with your SENDGRID_API_KEY, for example:
cp .env_sample .env
source .env Install PackageChoose your installation method - Maven w/ Gradle (recommended), Maven or Jar file. via Maven w/ GradleAdd the following to your build.gradle file in the root of your project. ...
dependencies {
...
implementation 'com.sendgrid:sendgrid-java:4.9.2'
}
repositories {
mavenCentral()
}
... via Maven
via jar fileYou can just drop the jar file in. It's a fat jar - it has all the dependencies built in. DependenciesQuick StartHello EmailThe following is the minimum needed code to send an email with the /mail/send Helper (here is a full example): With Mail Helper Classimport com.sendgrid.*;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
Email from = new Email("[email protected]");
String subject = "Sending with Twilio SendGrid is Fun";
Email to = new Email("[email protected]");
Content content = new Content("text/plain", "and easy to do anywhere, even with Java");
Mail mail = new Mail(from, subject, to, content);
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
try {
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody(mail.build());
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
} The Without Mail Helper ClassThe following is the minimum needed code to send an email without the /mail/send Helper (here is a full example): import com.sendgrid.*;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
try {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
Request request = new Request();
request.setMethod(Method.POST);
request.setEndpoint("mail/send");
request.setBody("{\"personalizations\":[{\"to\":[{\"email\":\"[email protected]\"}],\"subject\":\"Sending with Twilio SendGrid is Fun\"}],\"from\":{\"email\":\"[email protected]\"},\"content\":[{\"type\":\"text/plain\",\"value\": \"and easy to do anywhere, even with Java\"}]}");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
} General v3 Web API Usageimport com.sendgrid.*;
import java.io.IOException;
public class Example {
public static void main(String[] args) throws IOException {
SendGrid sg = new SendGrid(System.getenv("SENDGRID_API_KEY"));
try {
Request request = new Request();
request.setMethod(Method.GET);
request.setEndpoint("api_keys");
Response response = sg.api(request);
System.out.println(response.getStatusCode());
System.out.println(response.getBody());
System.out.println(response.getHeaders());
} catch (IOException ex) {
throw ex;
}
}
} Usage
Use CasesExamples of common API use cases, such as how to send an email with a transactional template. AnnouncementsAll updates to this library are documented in our CHANGELOG and releases. How to ContributeWe encourage contribution to our libraries (you might even score some nifty swag), please see our CONTRIBUTING guide for details. Quick links: TroubleshootingPlease see our troubleshooting guide for common library issues. Aboutsendgrid-java is maintained and funded by Twilio SendGrid, Inc. The names and logos for sendgrid-java are trademarks of Twilio SendGrid, Inc. SupportIf you need help installing or using the library, please check the Twilio SendGrid Support Help Center. License |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论