Best 3 Email API Code Examples Snippets (PHP, Python, Java)

Below are example codes for sending emails using the AotSend email API, divided into PHP, Python, and Java implementations. Please choose the appropriate reference example based on your programming language and integrate it according to your project's needs.

AOTsend Email API Tutorial: Email API Customer Tutorial Usage Guide Steps

AOTsend Email API Config Doc: AOTsend Email API Config Document


1. PHP Example reference code for calling the email API

$url = "https://www.aotsend.com/index/api/send_email";
$data = ['app_key'=>'', 'to'=>'', 'template_id'=>'', 'data'=>'{"name":"Jack","address":"New York"}'];

$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
if (!empty($data)){
    curl_setopt($curl, CURLOPT_POST, 1);
    curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
}
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$output = curl_exec($curl);
curl_close($curl);
var_dump($output);


2. Python Example reference code for calling the email API

url = 'https://www.aotsend.com/index/api/send_email'
# Set the data for the POST request
data = {
    'app_key': '',
    'to': '',
    'template_id': '',
    'data': '{"name":"Jack","address":"New York"}'
}
# Send a POST request
response = requests.post(url, data=data)
if response.status_code == 200:
    print(response.text)  # Print the returned text content
else:
    # Request failed; print the error message
    print(f'Error: {response.status_code}, {response.text}')


3. Java Example reference code for calling the email API

private static final String API_URL = "https://www.aotsend.com/index/api/send_email";
public static void main(String[] args) {
    // Create a CloseableHttpClient instance
    try (CloseableHttpClient httpClient = HttpClients.createDefault()) {
        // Create an HttpPost instance
        HttpPost httpPost = new HttpPost(API_URL);
        // Create a parameter list
        List<NameValuePair> params = new ArrayList<>();
        params.add(new BasicNameValuePair("app_key", ""));
        params.add(new BasicNameValuePair("template_id", ""));
        params.add(new BasicNameValuePair("to", ""));
        params.add(new BasicNameValuePair("reply_to", ""));
        params.add(new BasicNameValuePair("alias", ""));
        params.add(new BasicNameValuePair("data", "{\"name\":\"Jack\",\"address\":\"New York\"}"));
        UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(params, "UTF-8");
        httpPost.setEntity(formEntity);
        // Send the request and retrieve the response
        HttpResponse response = httpClient.execute(httpPost);
        // Read the response content
        HttpEntity responseEntity = response.getEntity();
        if (responseEntity != null) {
            String responseBody = EntityUtils.toString(responseEntity, "UTF-8");
            System.out.println("Response: " + responseBody);  
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}



In the digital age, efficient communication tools are key to a company's success. AotSend's email API provides a powerful and flexible platform that can be easily integrated for sending emails, whether you use PHP, Python, or Java. With the provided example code, developers can quickly deploy and optimize email sending processes based on their project needs. This not only enhances work efficiency but also ensures timely and accurate information delivery. As technology advances, AotSend's email API will continue to enhance its services to meet the evolving needs of developers and businesses, driving innovation and development in communication technology.