Code Examples
Here are the examples of sending emails with API V2 in different languages.
Python
send with template && address list
Java
WEBAPI_4.4 code example is dependent on httpclient4.4
<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>
WEBAPI_4.4 code example is dependent on 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>
SMTP_code example SMTP_code example
SMTP_code example SMTP_code example 2
PHP
template delivery &&address list
SMTP code is dependent on email delivery module. You need to install pear first.
pear installation steps:
Download installation package: curl -o go-pear.php http://pear.php.net/go-pear.phar
Install php go-pear.php
Install dependent libraries with pear:
pear install Mail
pear install Mail_Mime
pear install Net_SMTP
SMTP_code example 1 (quickly send,messageId is not required)
SMTP_code example 2 (messageId is required)
1.Find Mail/smyp.php file in php library
2.Change the returned value of “send” function in line 329. As shown below, change “return true” to “return $args”.
And then you can call following codes to send emails, and obtain messageId.
Ruby
rest_client is required for dependent code
gem install rest_client
template delivery&&address list
SMTP_code example 1 (quickly send,messageId is not required)
SMTP_code example 2 (messageId is required)
SMTP delivery is dependent on net/smtp.rb module. As module doesn’t return sever information by default after delivery, to obtain returned messageId, do the follows: First, find net/smtp.rb file in ruby library, and add a return value to the function data in line 915, details as below
Then, add a returned value to “send_message” in line 660. Details as below
Perl
Template delivery is dependent on json package.
Download at
https://metacpan.org/pod/JSON
template delivery &&address list
CSharp
template delivery &&attachment