Simple, declarative mail utility for sending mails with default smtp server or with custom channels.

Overview

Introduction

email-util is simple, declarative utility library. Key features are:

  • declarative email building;
  • text or html rendering;
  • annotation support for binding object value to template;
  • built-in smtp support for simple or multipart messages;
  • support for sending mails from other channels;

Download

For downloading dependency:

dependencies {
    implementation 'com.nicat.asgarzada:email-util:1.0.0'
}

Repository setting:

" password = project.findProperty("gpr.key") ?: " " } } } ">
repositories {
    maven {
        url = uri("https://maven.pkg.github.com/nasgarzada/mail-util")
        credentials {
            username = project.findProperty("gpr.user") ?: "
    
     "
    
            password = project.findProperty("gpr.key") ?: "
    
     "
    
        }
    }
}

In " " part add github your username. " " part generate personal access token for read packages.

Examples

Multipart mail sender

Following example shows multipart message building and sending:

public class Main {
    public static void main(String[] args) throws FileNotFoundException {
        Email.builder()
                .from("[email protected]")
                .to("[email protected]", false)
                .subject("Just testing my new library")
                .withRenderer()
                .path("template.txt")
                .bindingObject(new Example("Nijat Asgarzada"))
                .build()
                .withAttachment()
                .file("image.png")
                .build()
                .send(new MultipartMessageSender("email.properties"));
    }

    public static class Example {
        @Bind(key = "user")
        private String fullName;

        public Example(String fullName) {
            this.fullName = fullName;
        }

        public String getFullName() {
            return fullName;
        }

        public void setFullName(String fullName) {
            this.fullName = fullName;
        }

        @Override
        public String toString() {
            return "Example{" +
                    "fullName='" + fullName + '\'' +
                    '}';
        }
    }
}

In the example, you can see that, we have used built in MultipartMessageSender object for sending message. We passed properties file to object. Properties file is like that:

mail.smtp.auth=true
mail.smtp.starttls.enable=true

mail.smtp.host=smtp.gmail.com
mail.smtp.port=587
mail.username[email protected] 
mail.password= 

   mail.transport.protocol=smtp


   mail.content.type=text/html  
   #if you don't set default is text/plain

   mail.default.charset=UTF-8  
   #if you don't set it's default value
  

Another factor is @Bind(key = "user") annotation. This annotation enables replacing user field in template with value of fullName field of Example object.

Custom mail sender

Another key feature of util is customization of sender method. If you don't need sending via smtp, then you can implement your own logic. In the following example, I've implemented sending mail entity to queue:

public class QueueSender 
   implements 
   Sender<Void> {
    
   private 
   final 
   AmqpTemplate amqpTemplate;
    
   private 
   final 
   String queueName;
    
   private 
   final 
   ObjectMapper objectMapper;
    
    
   public 
   QueueSender(
   AmqpTemplate 
   amqpTemplate, 
   String 
   queueName, 
   ObjectMapper 
   objectMapper) {
        
   this
   .amqpTemplate 
   = amqpTemplate;
        
   this
   .queueName 
   = queueName;
        
   this
   .objectMapper 
   = objectMapper;
    }

    
   @Override
    
   public 
   Void 
   send(
   MailEntity 
   mailEntity) {
        
   this
   .amqpTemplate
   .convertAndSend(queueName, objectMapper
   .writeValueAsString(mailEntity));
        
   return 
   null;
    }
}


  
You might also like...

Fibers, Channels and Actors for the JVM

Quasar Fibers, Channels and Actors for the JVM Getting started Add the following Maven/Gradle dependencies: Feature Artifact Core (required) co.parall

Dec 25, 2022

tasks, async await, actors and channels for java

AsyncUtils tasks, async, await, actors and channels for java This project tries to explore several approaches to simplify async/concurrent programming

Dec 1, 2022

A Java library for capturing, crafting, and sending packets.

A Java library for capturing, crafting, and sending packets.

Japanese Logos Pcap4J Pcap4J is a Java library for capturing, crafting and sending packets. Pcap4J wraps a native packet capture library (libpcap, Win

Dec 30, 2022

A high-level and lightweight HTTP client framework for Java. it makes sending HTTP requests in Java easier.

A high-level and lightweight HTTP client framework for Java. it makes sending HTTP requests in Java easier.

A high-level and lightweight HTTP client framework for Java. it makes sending HTTP requests in Java easier.

Jan 8, 2023

An open-source OTP & Call flooding android application with unlimited sending capability.

An open-source OTP & Call flooding android application with unlimited sending capability.

Tsunami v1.3 An open-source SMS & Call flooding Android application with unlimited OTP bombing capability 📝 Notes ⚙ Click here for App Usage Guide Th

Jan 2, 2023

Daily mail subscription implementation using Java Spring-boot and Quartz Scheduler

Daily Mail Subscription Service POC Implemented using Java Spring-boot and Quartz Scheduler Working Application Exposing 3 endpoints /subscription/cre

Jun 3, 2022

A plugin of Grasscutter for send in-game mail conveniently

A plugin of Grasscutter for send in-game mail conveniently

MeaMailPlus - Grasscutter Mail enhancements MeaMailPlus is a plugin of Grasscutter, you can use this plugin to send your mail conveniently. English |

Dec 13, 2022

Envio automatizado de mensagens por e-mail.

Yara - Message in a Bottle Yara é uma aplicação que permite o envio de e-mails automatizados com mensagens pré-formatadas (ou não) a usuários cadastra

Jul 6, 2022

A declarative mapping library to simplify testable object mappings.

ReMap - A declarative object mapper Table of Contents Long story short About ReMap Great News Mapping operations Validation Features Limitations The m

Dec 27, 2022

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJO to JSON in a declarative way.

MapNeat is a JVM library written in Kotlin that provides an easy to use DSL (Domain Specific Language) for transforming JSON to JSON, XML to JSON, POJ

Sep 17, 2022

A declarative API to handle Android runtime permissions.

PermissionsDispatcher Fully Kotlin/Java support Special permissions support 100% reflection-free PermissionsDispatcher provides a simple annotation-ba

Jan 5, 2023

spark client is a utility mod for anarchy server made by dvd, geza3d and me

Spark-Client spark client is a utility mod for anarchy server made by dvd, geza3d and me.

Dec 11, 2022

A simple utility that allows you to query which items can be placed in a specific slot by holding down Left-Alt

A simple utility that allows you to query which items can be placed in a specific slot by holding down Left-Alt

What's That Slot This mod is a simple utility that allows you to query which items can be placed in a specific slot by holding down Left-Alt. You can

Dec 25, 2022

KC4Streams - a simple Java library that provides utility classes and standard implementations for most of the Kafka Streams pluggable interfaces

KC4Streams (which stands for Kafka Commons for Streams) is a simple Java library that provides utility classes and standard implementations for most of the Kafka Streams pluggable interfaces.

Mar 2, 2022
Releases(1.0.0)
Owner
Nijat Asgarzada
Nijat Asgarzada
Utility for developers and QAs what helps minimize time wasting on writing the same data for testing over and over again. Made by Stfalcon

Stfalcon Fixturer A Utility for developers and QAs which helps minimize time wasting on writing the same data for testing over and over again. You can

Stfalcon LLC 31 Nov 29, 2021
BFS utility

How to use Example (Usage for https://www.codingame.com/contests/spring-challenge-2021 usage) gameContext.getAllTree().stream().forEach(tree ->

Guillaume Rousseau 3 May 10, 2021
An utility to usage efficience ByteArray in Kotlin and Java.

An utility to usage efficience ByteArray in Kotlin and Java.

Cuong V. Nguyen 5 Sep 29, 2021
A utility for guessing the CCSID of files (based on file contents)

CcsidGuesser A utility for guessing the CCSID of files (based on file contents). It can also fix CCSID tags and/or convert files to UTF-8! Usage Usage

Jesse Gorzinski 4 Feb 21, 2022
🌏🎮 Integrate data provided from Minecraft server with Web API.

MCWebIntegration ?? ?? Integrate data provided from Minecraft server with Web API.

yude 2 Oct 14, 2021
A simple figura api extention that allow you to change your avatar, or upload it with script

A simple figura api extention that allow you to change your avatar, or upload it with script

null 4 Apr 14, 2022
Simple API, Complex Emails (JavaMail smtp wrapper)

Simple Java Mail Simple Java Mail is the simplest to use lightweight mailing library for Java, while being able to send complex emails including CLI s

Benny Bottema 1k Jan 5, 2023
Excel utility for Java to read and write data in declarative way.

Data Excel Exporter A Java wrapper using Apache POI to read and write Excel file in declarative fashion. Installation ExcelUtil is using Apache POI ve

null 27 Oct 16, 2022
JVM Profiler Sending Metrics to Kafka, Console Output or Custom Reporter

Uber JVM Profiler Uber JVM Profiler provides a Java Agent to collect various metrics and stacktraces for Hadoop/Spark JVM processes in a distributed w

Uber Common 1.7k Dec 22, 2022
WebSocket server with creatable/joinable channels.

bytesocks ?? bytesocks is a WebSocket server which allows clients to create "channels" and send messages in them. It's effectively an add-on for byteb

lucko 6 Nov 29, 2022