SendCloud 的 Java 开发包 sendcloud4j

码农软件 · 软件分类 · 网站API · 2019-03-09 08:42:50

软件介绍

sendcloud4j 是 SendCloud 邮件服务的 Java 语言封装包。

特点:

  • 支持 邮箱API v2 普通发送和模板发送

  • 支持批量发送(模板批量变量替换)

  • 支持添加附件发送

Maven

<dependency>
    <groupId>io.jstack</groupId>
    <artifactId>sendcloud4j</artifactId>
    <version>0.0.4</version>
<dependency>

Gradle

compile 'io.jstack:sendcloud4j:0.0.4'

示例代码:

  1. 初始化 API,通过 SendCloud 后台获取 apiUser 和 apiKey,创建 SendCloud 实例

    private String apiUser = "testApiUser";
    private String apiKey = "testApiKey";
    SendCloud webapi = SendCloud.createWebApi(apiUser, apiKey);
  2. 创建邮件实例,支持普通邮件和模板邮件。

    普通邮件,邮件内容支持 HTML 或文本:

    Email email = Email.general()
        .from("support@jstack.io")
        .fromName("JStack Support")
        .html("<b>Hello World!</b>")          // or .plain()
        .subject("mail title")
        .attachment(new File("att.png"))      // 添加附件 (File or byte[])
        .to("denger.it@gmail.com");

    模块邮件,使用 Substitution.sub() 替换变量值:

    Email email = Email.template("template_order_customer")
        .from("support@jstack.io")
        .fromName("JStack Support")
        .substitutionVars(Substitution.sub()  // 模板变量替换
                .set("product", "iPhone 6S")
                .set("name", "denger"))
        .attachment(new File("att.png"))      // 添加附件 (File or byte[])
        .to("denger.it@gmail.com");
  3. 执行发送

    Result result = webapi.mail().send(email);
  4. 处理发送结果

    result.isSuccess();      //API 请求是否成功
    result.getStatusCode();  //API 返回码
    result.getMessage();     //API 返回码的中文解释

本文地址:https://www.codercto.com/soft/d/948.html

The Filter Bubble

The Filter Bubble

Eli Pariser / Penguin Press / 2011-5-12 / GBP 16.45

In December 2009, Google began customizing its search results for each user. Instead of giving you the most broadly popular result, Google now tries to predict what you are most likely to click on. Ac......一起来看看 《The Filter Bubble》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换