### Building java-sparkpost Project (Maven) Source: https://github.com/sparkpost/java-sparkpost/blob/master/CONTRIBUTING.md This Maven command performs a clean build and installation of the `java-sparkpost` project. It compiles source code, runs tests, and installs the resulting artifacts into the local Maven repository, preparing the project for use or further development. ```Maven mvn clean install ``` -------------------------------- ### Setting SparkPost API Environment Variables (Shell) Source: https://github.com/sparkpost/java-sparkpost/blob/master/CONTRIBUTING.md These shell commands set the necessary environment variables for the `java-sparkpost` examples and API interactions. `SPARKPOST_API_KEY` stores your SparkPost API key, and `SPARKPOST_SENDER_EMAIL` defines the 'From' address for sending emails, both crucial for authentication and functionality. ```Shell SPARKPOST_API_KEY="YOUR_SPARKPOST_API_KEY" SPARKPOST_SENDER_EMAIL="YOUR_EMAIL_FROM_ADDRESS" ``` -------------------------------- ### Sending Basic Email via SparkPost EU Endpoint (Java) Source: https://github.com/sparkpost/java-sparkpost/blob/master/README.md This Java example illustrates how to configure the SparkPost Java client to send emails through the SparkPost EU endpoint. It initializes the Client with an API key and explicitly sets the IRestConnection.SPC_EU_ENDPOINT for the EU region. ```Java package com.sparkpost; import com.sparkpost.exception.SparkPostException; import com.sparkpost.transport.IRestConnection; public class SparkPost { public static void main(String[] args) throws SparkPostException { String API_KEY = "YOUR API KEY HERE!!!"; // To use the SparkPost EU use the IRestConnection.SPC_EU_ENDPOINT endpoint Client client = new Client(API_KEY, IRestConnection.SPC_EU_ENDPOINT); client.sendMessage( "you@yourdomain.com", "to@sparkpost.com", "The subject of the message", "The text part of the email", "The HTML part of the email"); } } ``` -------------------------------- ### Building SparkPost Java Sample Applications - Bash Source: https://github.com/sparkpost/java-sparkpost/blob/master/README.md This snippet provides the bash commands to navigate to the sample application directory and compile the Java source code using Maven. This step is a prerequisite for running any of the sample applications. ```bash cd apps/sparkpost-samples-app mvn compile ``` -------------------------------- ### Running a Specific SparkPost Java Sample Application - Bash Source: https://github.com/sparkpost/java-sparkpost/blob/master/README.md This command executes a specific SparkPost Java sample application, `SendEmailCCSample`, using Maven's `exec:java` plugin. Ensure `config.properties` is set up with your API key before running. ```bash mvn exec:java -Dexec.mainClass=com.sparkpost.samples.SendEmailCCSample ``` -------------------------------- ### Setting up Lombok for Eclipse (Shell) Source: https://github.com/sparkpost/java-sparkpost/blob/master/CONTRIBUTING.md This shell script is used to configure Project Lombok within the Eclipse IDE for the `java-sparkpost` project. Lombok helps reduce boilerplate code in Java, and this step ensures proper integration for development in Eclipse. ```Shell ./tools/bin/setupLombok.sh ``` -------------------------------- ### Cloning java-sparkpost Repository (Git) Source: https://github.com/sparkpost/java-sparkpost/blob/master/CONTRIBUTING.md This Git command clones the `java-sparkpost` project from its GitHub repository to your local machine. It's the initial step to obtain the source code for local development and contributions. ```Git git clone https://github.com/sparkpost/java-sparkpost ``` -------------------------------- ### Running Project Tests (Maven) Source: https://github.com/sparkpost/java-sparkpost/blob/master/CONTRIBUTING.md This Maven command executes all unit and integration tests defined within the `java-sparkpost` project. It's essential for verifying code changes and ensuring the stability and correctness of the application during development and before submitting contributions. ```Maven mvn clean install ``` -------------------------------- ### Sending Basic Email with SparkPost Java Client Source: https://github.com/sparkpost/java-sparkpost/blob/master/README.md This Java code demonstrates how to send a basic email using the SparkPost Java client. It initializes a Client with an API key and uses the sendMessage method to send an email with specified sender, recipient, subject, text, and HTML content. ```Java package com.sparkpost; import com.sparkpost.exception.SparkPostException; public class SparkPost { public static void main(String[] args) throws SparkPostException { String API_KEY = "YOUR API KEY HERE!!!"; Client client = new Client(API_KEY); client.sendMessage( "you@yourdomain.com", "to@sparkpost.com", "The subject of the message", "The text part of the email", "The HTML part of the email"); } } ``` -------------------------------- ### Sending Advanced Email with Recipient Array and Substitution Data (Java) Source: https://github.com/sparkpost/java-sparkpost/blob/master/README.md This Java method demonstrates advanced email sending capabilities using the SparkPost Java library. It shows how to populate multiple recipients, add substitution data for templating, and define rich content (subject, text, HTML) for the email. It requires a Client instance and an endpoint. ```Java private void sendEmail(String from, String[] recipients, String email) throws SparkPostException { TransmissionWithRecipientArray transmission = new TransmissionWithRecipientArray(); // Populate Recipients List recipientArray = new ArrayList(); for (String recipient : recipients) { RecipientAttributes recipientAttribs = new RecipientAttributes(); recipientAttribs.setAddress(new AddressAttributes(recipient)); recipientArray.add(recipientAttribs); } transmission.setRecipientArray(recipientArray); // Populate Substitution Data Map substitutionData = new HashMap(); substitutionData.put("yourContent", "You can add substitution data too."); transmission.setSubstitutionData(substitutionData); // Populate Email Body TemplateContentAttributes contentAttributes = new TemplateContentAttributes(); contentAttributes.setFrom(new AddressAttributes(from)); contentAttributes.setSubject("Your subject content here. {{yourContent}}"); contentAttributes.setText("Your Text content here. {{yourContent}}"); contentAttributes.setHtml("

Your HTML content here. {{yourContent}}

"); transmission.setContentAttributes(contentAttributes); // Send the Email RestConnection connection = new RestConnection(client, getEndPoint()); Response response = ResourceTransmissions.create(connection, 0, transmission); logger.debug("Transmission Response: " + response); } ``` -------------------------------- ### Adding SparkPost Java Library Dependency (Maven) Source: https://github.com/sparkpost/java-sparkpost/blob/master/README.md This XML snippet shows how to include the SparkPost Java Library as a dependency in a Maven project's pom.xml file. It specifies the groupId, artifactId, and version required for the library. ```XML com.sparkpost sparkpost-lib 0.27 ``` -------------------------------- ### Applying Responsive Styles for Mobile - CSS Source: https://github.com/sparkpost/java-sparkpost/blob/master/apps/sparkpost-samples-app/samples/richContent.html This CSS snippet defines responsive styles for email templates, specifically targeting screens with a maximum width of 480px. It adjusts table widths, image sizes, and element display properties to ensure proper rendering on mobile devices. ```CSS @media(max-width:480px){ table[class=main_table],table[class=layout_table],table[class=header_table]{width:300px !important;} table[class=layout_table] tbody tr td.header_image img{width:300px !important;height:auto !important;} table[class=logo_table],table[class=company_table]{display:block !important;width:220px !important;} table[class=logo_table] tbody tr td,table[class=company_table] tbody tr td{width:220px !important;} table[class=company_table] tbody tr td span{text-align:center !important;} table[class=footer_table] tbody tr td.border_image img{width:300px !important;height:2.5px !important;} } ``` -------------------------------- ### Styling Hyperlinks - CSS Source: https://github.com/sparkpost/java-sparkpost/blob/master/apps/sparkpost-samples-app/samples/richContent.html This CSS rule sets the color of all anchor () tags to a specific blue shade (#37aadc), ensuring consistent link styling within the email template. ```CSS a{color:#37aadc} ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.