GithubHelp home page GithubHelp logo

sendcloud4j's Introduction

SendCloud SDK For Java Maven Central

Travis CI Build Status Coverage Status

SendCloud SDK For Java

  • 支持 邮箱API v2 普通发送和模板发送
  • 支持批量发送(模板批量变量替换)
  • 支持添加附件发送
  • 支持使用 HTTP 代理发送

Quick Start

Maven
<dependency>
	<groupId>io.jstack</groupId>
	<artifactId>sendcloud4j</artifactId>
	<version>0.0.5</version>
<dependency>
Gradle
compile 'io.jstack:sendcloud4j:0.0.5'
代码示例
  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("[email protected]")
        .fromName("JStack Support")
        .html("<b>Hello World!</b>")          // or .plain()
        .subject("mail title")
        .attachment(new File("att.png"))      // 添加附件 (File or byte[])
        .to("[email protected]");

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

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

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

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

FQA

如何使用代理发送邮件?

在发送邮件时通过 viaProxy 方法指定代码 ip 和端口,如下所示:

Result result = webapi.mail().viaProxy("example_ip:port").send(email);

如果你有新需求或问题欢迎提 issues 或 fork :)

sendcloud4j's People

Contributors

denger avatar akirapanda avatar imhuzi avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.