Java Sendmail

A simple Java send email library

License

License

Categories

Categories

Java Languages
GroupId

GroupId

com.johnpili
ArtifactId

ArtifactId

java-sendmail
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Java Sendmail
A simple Java send email library
Project URL

Project URL

https://github.com/johnpili/java-sendmail.git

Download java-sendmail

How to add to project

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

Dependencies

compile (2)

Group / Artifact Type Version
javax.mail : mail jar 1.4.7
javax.mail : javax.mail-api jar 1.5.4

Project Modules

There are no modules declared in this project.

java-sendmail

A simple java send email library

Usage example

Sendmail sendmail = new Sendmail.Config()
    .properties(properties)
    .from(from)
	.to(targetRecipient)
	.subject(subject)
	.textMessagePart(plainTextMessage)
	.htmlMessagePart(htmlMessage)
	.smtpUsername(appConfig.getSmtpUsername())
	.smtpPassword(appConfig.getSmtpPassword())
	.build();

new Thread(sendmail).start();
## Code example in a service method

public void sendEmailNotification(String targetRecipient, String subject, String plainTextMessage, String htmlMessage)
	{
		try
		{
			String from = "johnpili.com <[email protected]>";
			String host = appConfig.getSmtpHost();
			String port = appConfig.getSmtpPort();

			Properties properties = System.getProperties();
			properties.put("mail.transport.protocol", "smtp");
			properties.put("mail.smtp.socketFactory.port", port);
			properties.put("mail.smtp.socketFactory.class",
					"javax.net.ssl.SSLSocketFactory");
			properties.put("mail.smtp.host", host);
			if (appConfig.isSmtpRequireAuthentication())
			{
				properties.put("mail.smtp.auth", "true");
			}
			properties.put("mail.smtp.port", port);

			Sendmail sendmail = new Sendmail.Config()
					.properties(properties)
					.from(from)
					.to(targetRecipient)
					.subject(subject)
					.textMessagePart(plainTextMessage)
					.htmlMessagePart(htmlMessage)
					.smtpUsername(appConfig.getSmtpUsername())
					.smtpPassword(appConfig.getSmtpPassword())
					.build();

			new Thread(sendmail).start();
		}
		catch (Exception exception)
		{
			logger.error("sendEmailNotification Error: " + exception.getMessage());
		}
	}
  
  

Versions

Version
1.0.1