MockMail

Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/

GroupId

GroupId

br.com.otavio
ArtifactId

ArtifactId

mockmail
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

MockMail
Sonatype helps open source projects to set up Maven repositories on https://oss.sonatype.org/
Project URL

Project URL

https://github.com/garcia-jj/mockmail
Source Code Management

Source Code Management

https://github.com/garcia-jj/mockmail

Download mockmail

How to add to project

<!-- https://jarcasting.com/artifacts/br.com.otavio/mockmail/ -->
<dependency>
    <groupId>br.com.otavio</groupId>
    <artifactId>mockmail</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/br.com.otavio/mockmail/
implementation 'br.com.otavio:mockmail:0.0.1'
// https://jarcasting.com/artifacts/br.com.otavio/mockmail/
implementation ("br.com.otavio:mockmail:0.0.1")
'br.com.otavio:mockmail:jar:0.0.1'
<dependency org="br.com.otavio" name="mockmail" rev="0.0.1">
  <artifact name="mockmail" type="jar" />
</dependency>
@Grapes(
@Grab(group='br.com.otavio', module='mockmail', version='0.0.1')
)
libraryDependencies += "br.com.otavio" % "mockmail" % "0.0.1"
[br.com.otavio/mockmail "0.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
javax.mail : javax.mail-api jar 1.5.4
com.sun.mail : javax.mail jar 1.5.3

test (1)

Group / Artifact Type Version
junit : junit jar 4.8.2

Project Modules

There are no modules declared in this project.

Mockmail

Mockmail is a simple JavaMail provider to allow you to prevent sending e-mail messages using a real transport, useful when we are testing an application. There are providers to print the message into system console or in a file.

How to install

If you are using Maven as dependency manager you only need to add this line in your pom.xml:

<dependency>
	<groupId>br.com.otavio</groupId>
	<artifactId>mockmail</artifactId>
	<version>0.0.1</version>
</dependency>

Or you can also download the artifact here.

How to use

SysoutTransport

Allow you to print the e-mail message using system console.

public static void main(String[] args) throws Exception {
	final Properties props = new Properties();
	props.put("mail.transport.protocol", "sysout");

	final Session session = Session.getInstance(props);
	final Message msg = new MimeMessage(session);
	msg.setRecipient(Message.RecipientType.TO, new InternetAddress(randomEmail()));
	msg.setFrom(new InternetAddress(randomEmail()));
	msg.setSubject("teste");
	msg.setContent("teste", "text/plain");
	msg.saveChanges();

	session.getTransport().sendMessage(msg, msg.getAllRecipients());
}

FileTransport

Allow you to print the e-mail message into a file.

public static void main(String[] args) throws Exception {
	final Properties props = new Properties();
	props.put("mail.transport.protocol", "file");
	props.put("mail.transport.file.path", "/tmp/maillog.txt");
	props.put("mail.transport.file.append", "false");

	final Session session = Session.getInstance(props);

	final Message msg = new MimeMessage(session);
	msg.setRecipient(Message.RecipientType.TO, new InternetAddress(randomEmail()));
	msg.setFrom(new InternetAddress(randomEmail()));
	msg.setSubject("teste");
	msg.setContent("teste", "text/plain");
	msg.saveChanges();

	session.getTransport().sendMessage(msg, msg.getAllRecipients());
}

Versions

Version
0.0.1