# 代码示例

以下为各种语言使用 API V2 发送邮件的示例.

# Python

普通发送

附件发送

模板发送

模板发送&&地址列表

# Java

依赖 WEBAPI_4.2代码示例需要依赖如下jar包 httpclient4.2

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.2</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.2</version>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20140107</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

WEBAPI_4.4代码示例需要依赖如下jar包 httpclient4.4

<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.4</version>
</dependency>
<dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpmime</artifactId>
    <version>4.4</version>
</dependency>
<dependency>
    <groupId>org.json</groupId>
    <artifactId>json</artifactId>
    <version>20140107</version>
</dependency>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

httpclient (opens new window) httpmime (opens new window) org.json (opens new window)

WEBAPI_4.2代码示例
WEBAPI_4.4代码示例

# PHP

普通发送

普通发送_curl

普通发送&&附件

模板发送

模板发送&&地址列表

# Ruby

依赖 代码需要安装rest-client

gem install 'rest-client'
1

普通发送

普通发送&&附件

模板发送

模板发送&&地址列表

# Perl

依赖 模板发送需要依赖json包

从CPAN下载安装
https://metacpan.org/pod/JSON
1
2

普通发送

普通发送&&附件

模板发送

模板发送&&地址列表

# CSharp

普通发送

普通发送&&附件

模板发送

模板发送&&附件

# Go

普通发送

附件发送

模板发送

# Nodejs

package.json

{
  "name": "1.node-demo",
  "version": "1.0.0",
  "description": "",
  "main": "1.sendEmail.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "axios": "^1.1.3",
    "form-data": "^4.0.0",
    "nodemailer": "^6.8.0"
  }
}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

普通发送

附件发送

xsmtpapi发送

上次更新: 2025/03/25 10:38:59