### Run Basic SubEthaSMTP Server Source: https://github.com/davidmoten/subethasmtp/blob/master/GettingStarted.md Execute this command to start a basic SubEthaSMTP server. Ensure the specified JAR file is in your classpath. The server will listen on TCP port 25000. ```bash java -cp subethasmtp-j3.1.8-jar-with-dependencies.jar org.subethamail.examples.BasicSMTPServer ``` -------------------------------- ### Start a basic SMTP server Source: https://github.com/davidmoten/subethasmtp/blob/master/README.md Initializes and starts an SMTP server on a specified port. ```java SMTPServer server = SMTPServer .port(25000) .build(); //start server asynchronously server.start(); ``` -------------------------------- ### Eclipse Maven Project Setup Source: https://github.com/davidmoten/subethasmtp/blob/master/GettingStarted.md Steps to import and build the SubEthaSMTP project in Eclipse using Maven. This involves cloning the repository and running 'Maven Install'. ```xml Import->Maven->Existing Maven Projects Right click on the POM.XML file and select Run As->Maven Install ``` -------------------------------- ### Initialize and Start Basic SMTP Server Source: https://github.com/davidmoten/subethasmtp/blob/master/UsingSubEthaSMTP.md Configures and starts an SMTP server using the basic API with a custom message handler factory. ```java SMTPServer smtpServer = SMTPServer.port(25).messageHandlerFactory(myFactory).build(); smtpServer.start(); ``` -------------------------------- ### Initialize Server with SimpleMessageListenerAdapter Source: https://github.com/davidmoten/subethasmtp/blob/master/UsingSubEthaSMTP.md Uses the higher-level SimpleMessageListenerAdapter to simplify message handling. ```java SMTPServer server = SMTPServer .port(25) .messageHandlerFactory(new SimpleMessageListenerAdapter(myListener)) .build(); server.start(); ``` -------------------------------- ### Configure advanced SMTP server options Source: https://github.com/davidmoten/subethasmtp/blob/master/README.md Demonstrates various builder methods for tuning server behavior, including timeouts, TLS, and connection limits. ```java SMTPServer server = SMTPServer .port(port) .connectionTimeout(1, TimeUnit.MINUTES) .authenticationHandlerFactory(ahf) .backlog(100) .bindAddress(address) .requireTLS() .hideTLS() .hostName("us") .maxMessageSize(10000) .maxConnections(20) .maxRecipients(20) .messageHandlerFactory(mhf) .executorService(executor) .startTlsSocketFactory(sslContext) .fromAddressValidator(emailValidator) .build(); ``` -------------------------------- ### Configure SMTP Authentication Source: https://github.com/davidmoten/subethasmtp/blob/master/UsingSubEthaSMTP.md Sets up an SMTP server with an authentication handler factory for handling AUTH commands. ```java SMTPServer server = SMTPServer .port(port) .messageHandlerFactory(myMessageHandlerFactory); .authenticationHandlerFactory(new EasyAuthenticationHandlerFactory(myUsernamePasswordValidator)) .build(); server.start(); ``` -------------------------------- ### Handle incoming SMTP messages Source: https://github.com/davidmoten/subethasmtp/blob/master/README.md Configures a message handler to process incoming email data as a byte array. ```java SMTPServer server = SMTPServer // .port(PORT) // .messageHandler( (ctx, from, to, data) -> System.out.println( "message from " + from + " to " + to + ":\n" + new String(data, StandardCharsets.UTF_8))) .build(); server.start(); ``` -------------------------------- ### SimpleMessageListener Interface Source: https://github.com/davidmoten/subethasmtp/blob/master/UsingSubEthaSMTP.md Provides a simplified interface for accepting recipients and delivering message data. ```java public interface SimpleMessageListener { /** * Called once for every RCPT TO during a SMTP exchange. Each accepted recipient * will result in a separate deliver() call later. */ public boolean accept(String from, String recipient); /** * When message data arrives, this method will be called for every recipient * this listener accepted. */ public void deliver(String from, String recipient, InputStream data) throws TooMuchDataException, IOException; } ``` -------------------------------- ### MessageHandler and Factory Interfaces Source: https://github.com/davidmoten/subethasmtp/blob/master/UsingSubEthaSMTP.md Defines the low-level interfaces for creating message handlers and processing SMTP transaction stages. ```java public interface MessageHandlerFactory { /** * Called for the exchange of a single message during an SMTP conversation. */ public MessageHandler create(MessageContext ctx); } public interface MessageHandler { /** * Called first, after the MAIL FROM during a SMTP exchange. */ public void from(String from) throws RejectException; /** * Called once for every RCPT TO during a SMTP exchange. * This will occur after a from() call. */ public void recipient(String recipient) throws RejectException; /** * Called when the DATA part of the SMTP exchange begins. */ public void data(InputStream data) throws RejectException, TooMuchDataException, IOException; } ``` -------------------------------- ### Add SubEthaSMTP Maven Dependency Source: https://github.com/davidmoten/subethasmtp/blob/master/ObtainingSubEthaSMTP.md Include this dependency in your project's POM file to use the SubEthaSMTP library. Adjust the version number as needed. ```xml com.github.davidmoten subethasmtp VERSION_HERE ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.