Sending email in Java using Smtp API

Experience a breakthrough in your development process with TurboSMTP's Email API. Achieve swift integration and instant email dispatch. Our API, compatible with any Java application, streamlines large-scale email sending with easy-to-follow documentation.

Sending email in Java using Smtp API

Email API for Java Developers

TurboSMTP's Email API simplifies the integration of email functionalities into your Java applications. Featuring a user-friendly API, smooth integration, and detailed documentation, it enables you to efficiently scale your email delivery, from a couple of emails to millions. Below, you'll find straightforward examples demonstrating the integration of our APIs with Java applications.

import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;

public class TurboSMTPMailExample {
    public static void main(String[] args) {
        try {
            // Specify the URL of the API endpoint
            URL url = new URL("https://api.turbo-smtp.com/api/v2/mail/send");

            // Specify Credentials
            String Consumerkey = "<CONSUMER_KEY>";
            String Consumersecret = "<CONSUMER_SECRET>";

            // Open a connection to the URL
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();

            // Set the request method to POST
            connection.setRequestMethod("GET");

            // Set the request headers
            connection.setRequestProperty("Content-Type", "application/json");
            connection.setRequestProperty("Accept", "application/json");
            connection.setRequestProperty("Consumerkey", Consumerkey);
            connection.setRequestProperty("Consumersecret", Consumersecret);

            // Enable input and output streams
            connection.setDoInput(true);
            connection.setDoOutput(true);

            // Define the request body (as JSON)
            //String requestBody = "{\"from\": \"user@example.com\", \"to\": \"user@example.com,user2@example.com\", \"subject\": \"This is a test message\"}";
            
            String requestBody = "{" +
                                "\"from\": \"user@example.com\", " +
                                "\"to\": \"user@example.com,user2@example.com\", " +
                                "\"subject\": \"This is a test message\", " +
                                "\"cc\": \"cc_user@example.com\", " +
                                "\"bcc\": \"bcc_user@example.com\", " +
                                "\"content\": \"Dear partner. We are delighted to invite you to an exclusive training session on UX Design. This session is designed to provide essential insights and practical strategies to enhance your skills.\", " +
                                "\"html_content\": \"Dear partner,<br />We are delighted to invite you to an exclusive training session on <strong>UX Design</strong>. This session is designed to provide essential insights and practical strategies to enhance your skills.\" " +
                                "}";            
            
            DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
            outputStream.writeBytes(requestBody);
            outputStream.flush();
            outputStream.close();

            // Get the response code
            int responseCode = connection.getResponseCode();

            // Read the response from the server
            BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String line;
            StringBuilder response = new StringBuilder();
            while ((line = reader.readLine()) != null) {
                response.append(line);
            }
            reader.close();

            // Print the response
            System.out.println("Response Code: " + responseCode);
            System.out.println("Response Body: " + response.toString());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Send Emails Using Your Favorite Coding Language

Our APIs offer developers the flexibility to effortlessly integrate email solutions using their preferred programming languages. Whether you're skilled in Python, cURL, Ruby, or any other popular coding language, our comprehensive API support has you covered.

TurboSMTP Service Highlights

Here are four compelling reasons to choose TurboSMTP's service: unparalleled email delivery, data-driven insights through analytics, robust privacy and security, and dedicated 24/7 support for a worry-free email experience.

Powerful Infrastructure for High Email Deliverability

Our infrastructure scales for mass email distribution, offering SMTP and API integration, with TurboSMTP ensuring fast, effective communication.

Refine Outreach with Email Metrics & Analytics

TurboSMTP's tools provide insights on email performance, helping optimize campaigns for better engagement, conversions, and ROI through data-driven strategies.

Email Privacy and Security: Fundamental Values

Our email service prioritizes privacy and security, using advanced encryption and strict privacy law adherence to protect your data and communications.

Support at Your Service Whenever You Want

TurboSMTP provides 24/7 collaborative support with a dedicated team, ensuring a smooth, worry-free email experience and reliable assistance at every step.

Get Started with TurboSMTP Email API

Just follow these three simple steps to seamlessly integrate TurboSMTP into your Java application.

Sign up for a free account and get 10,000 free emails per month.

Retrieve your API key from your dashboard.

Follow our API documentation to start your integration.