SubEtha SMTP is a Java library which allows your application to receive SMTP mail with a simple, easy-to-understand API. I use it as Mock SMTP server for CI (Continuous Integration) in a Spring project.
This is applicationContext-email.xml:
<!-- In order to not port clash set port 0 so JVM will bind to any free port then refer to the resolver port -->
<bean id="mockSMTPServer" class="org.subethamail.wiser.Wiser" init-method="start" destroy-method="stop">
<property name="port" value="0" />
</bean>
<bean id="mailSender" class="org.springframework.beans.factory.config.BeanReferenceFactoryBean">
<property name="targetBeanName" value="mailSender${mail.smtp.service}" />
</bean>
<bean id="mailSenderImpl" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="${mail.host}" />
</bean>
<bean id="mailSenderMock" class="org.springframework.mail.javamail.JavaMailSenderImpl">
<property name="host" value="#{mockSMTPServer.server.hostName}" />
<property name="port" value="#{mockSMTPServer.server.port}" />
</bean>
In applicationContext.xml set to Impl (Spring email service implementation) or Mock (mocked email service):
mail.smtp.service=[Impl|Mock]
» Read more: Mock SMTP server / email service





