What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

To send email from a Spring Boot application through SendGrid, add the official sendgrid-java SDK, keep a restricted SendGrid API key outside your source code, verify the sender address or domain, and call SendGrid’s v3 Mail Send API from a Spring-managed service.

What you need before integrating

  • A SendGrid account and an API key with the Mail Send permission required by the application. SendGrid recommends API keys rather than account credentials and says to treat keys like passwords: API key documentation.
  • A verified sender identity. Single Sender Verification is intended for testing; SendGrid recommends Domain Authentication for production sending and notes that recipient-domain DMARC policies can affect delivery from unaligned or unverified sender domains. See the sender identity guide.
  • An application environment that can make outbound HTTPS requests to SendGrid’s API.

The Java quickstart’s example dependency is version 4.10.3, but that is an example rather than a claim about the latest release. Check the official Java SDK releases and current compatibility details before choosing a version. The official quickstart is available at SendGrid’s Java quickstart.

Add the SendGrid Java SDK

For Maven, add the dependency to pom.xml, substituting the current version you have confirmed from the official release source:

<dependency>
  <groupId>com.sendgrid</groupId>
  <artifactId>sendgrid-java</artifactId>
  <version>4.10.3</version>
</dependency>

The version shown matches the Java quickstart sample surfaced on September 30, 2026; do not assume it remains current. The SDK submits requests to SendGrid’s v3 API, whose documented base URL is https://api.sendgrid.com/v3/.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Configure the API key outside the repository

Set the key as an environment variable in the runtime or deployment platform, or use a secret manager. For example, the variable name can be SENDGRID_API_KEY. Do not put the actual key in checked-in application.properties, Java code, container images, or logs. SendGrid’s getting-started documentation describes API-key authorization and the Java environment-variable pattern.

Spring Boot can resolve an environment variable through a property placeholder, letting the service depend on configuration rather than reading process state throughout the application:

# application.properties
sendgrid.api-key=${SENDGRID_API_KEY}

Make sure SENDGRID_API_KEY is present in each environment where the application runs. A missing or invalid key will prevent successful API authorization. Restrict the key to Mail Send if that is all the service needs; revoke and replace it if it is exposed.

Build a Spring-managed mail service

This example uses the SDK’s Mail, Email, and Content types and sends a plain-text message. The sender address must match a verified sender identity in your SendGrid account.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
import com.sendgrid.Method;
import com.sendgrid.Request;
import com.sendgrid.Response;
import com.sendgrid.SendGrid;
import com.sendgrid.helpers.mail.Mail;
import com.sendgrid.helpers.mail.objects.Content;
import com.sendgrid.helpers.mail.objects.Email;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.io.IOException;

@Service
public class SendGridMailService {
    private final SendGrid sendGrid;
    private final String fromAddress;

    public SendGridMailService(
            @Value("${sendgrid.api-key}") String apiKey,
            @Value("${sendgrid.from-address}") String fromAddress) {
        this.sendGrid = new SendGrid(apiKey);
        this.fromAddress = fromAddress;
    }

    public Response sendText(String toAddress, String subject, String body)
            throws IOException {
        Email from = new Email(fromAddress);
        Email to = new Email(toAddress);
        Content content = new Content("text/plain", body);
        Mail mail = new Mail(from, subject, to, content);

        Request request = new Request();
        request.setMethod(Method.POST);
        request.setEndpoint("mail/send");
        request.setBody(mail.build());

        return sendGrid.api(request);
    }
}

Configure the sender address separately, for example with sendgrid.from-address in environment-backed configuration. As with the API key, keep deployment-specific values and secrets out of source control. This service can be injected into application code that needs to send a notification or other transactional email.

Check the API response and handle failures

The SDK call returns a response containing a status code, body, and headers. Treat that response as the result of the API request, not proof that a recipient’s inbox received or displayed the email.

Response response = sendGridMailService.sendText(
    "recipient@example.com",
    "Your report is ready",
    "The report is available in your account."
);

if (response.getStatusCode() < 200 || response.getStatusCode() >= 300) {
    // Record a useful failure signal and apply your application's error policy.
}

In a production application, decide how the caller should respond to API errors and I/O failures: for example, propagate an application exception, retry only when appropriate, or record a failed notification for later handling. Log operational details such as status code and a correlation identifier when available, but never log the API key or unnecessarily expose message content or personal data.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Choose and verify the sender identity

Option Best fit What to know
Single Sender Verification Testing Verifies an individual sending address. SendGrid positions this as a testing option; it does not provide the same domain-level authentication as Domain Authentication.
Domain Authentication Production sending domain SendGrid’s recommended production route. Properly aligned sender domains matter because recipient-domain DMARC policies can affect delivery.

Use the setup flow in the sender identity documentation and complete the required verification before relying on the address in application mail.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Account for message size and delivery scope

SendGrid’s API Getting Started documentation states that the total message size—including the message, headers, and combined attachments—should not exceed 20 MB. Keep attachment handling within that documented limit: API Getting Started.

A successful API response means SendGrid accepted the request according to the response returned by the API; it does not establish inbox placement. Sender verification, recipient-side policies, and other delivery factors remain relevant.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.