├── UIDesign └── main.xd ├── screenshots ├── fxmailer_main.png ├── fxmailer_status.png └── template_sample.png ├── src └── main │ ├── resources │ ├── template │ │ ├── body-end.txt │ │ ├── end.txt │ │ ├── header.txt │ │ ├── body-start.txt │ │ ├── footer.txt │ │ └── begin.txt │ ├── css │ │ └── main.css │ └── fxml │ │ └── Main.fxml │ └── java │ └── com │ └── houarizegai │ └── fxmailer │ ├── util │ ├── Constants.java │ └── Tools.java │ ├── engine │ ├── MarkdownParser.java │ ├── TemplateBuilder.java │ └── EmailEngine.java │ ├── model │ └── Receiver.java │ ├── App.java │ └── controller │ └── MainController.java ├── .gitignore ├── README.md ├── pom.xml └── LICENSE /UIDesign/main.xd: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HouariZegai/FXMailer/HEAD/UIDesign/main.xd -------------------------------------------------------------------------------- /screenshots/fxmailer_main.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HouariZegai/FXMailer/HEAD/screenshots/fxmailer_main.png -------------------------------------------------------------------------------- /screenshots/fxmailer_status.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HouariZegai/FXMailer/HEAD/screenshots/fxmailer_status.png -------------------------------------------------------------------------------- /screenshots/template_sample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/HouariZegai/FXMailer/HEAD/screenshots/template_sample.png -------------------------------------------------------------------------------- /src/main/resources/template/body-end.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Intellij 2 | .idea/ 3 | out/ 4 | *.iml 5 | 6 | # Maven 7 | target/ 8 | log/ 9 | 10 | # Other 11 | resource_files/ -------------------------------------------------------------------------------- /src/main/resources/template/end.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /src/main/resources/template/header.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
%s
6 | 7 | -------------------------------------------------------------------------------- /src/main/resources/template/body-start.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 3 | 11 | 12 | -------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/engine/MarkdownParser.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer.engine; 2 | 3 | import com.vladsch.flexmark.html.HtmlRenderer; 4 | import com.vladsch.flexmark.parser.Parser; 5 | 6 | public class MarkdownParser { 7 | private static Parser parser; 8 | private static HtmlRenderer renderer; 9 | 10 | static { 11 | parser = Parser.builder().build(); 12 | renderer = HtmlRenderer.builder().build(); 13 | } 14 | 15 | public static String toHtml(String content) { // convert: Markdown > HTML 16 | if(content == null) 17 | return ""; 18 | 19 | return renderer.render(parser.parse(content)); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/model/Receiver.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer.model; 2 | 3 | public class Receiver { 4 | private String name; 5 | private String email; 6 | 7 | public Receiver() { 8 | } 9 | 10 | public String getName() { 11 | return name; 12 | } 13 | 14 | public void setName(String name) { 15 | this.name = name; 16 | } 17 | 18 | public String getEmail() { 19 | return email; 20 | } 21 | 22 | public void setEmail(String email) { 23 | this.email = email; 24 | } 25 | 26 | @Override 27 | public String toString() { 28 | return "name: " + name + ", email: " + email; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/App.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer; 2 | 3 | import javafx.application.Application; 4 | import javafx.fxml.FXMLLoader; 5 | import javafx.scene.Parent; 6 | import javafx.scene.Scene; 7 | import javafx.stage.Stage; 8 | 9 | import java.io.IOException; 10 | 11 | public class App extends Application { 12 | public static Stage stage; 13 | @Override 14 | public void start(Stage stage) { 15 | try { 16 | Parent root = FXMLLoader.load(getClass().getResource("/fxml/Main.fxml")); 17 | stage.setScene(new Scene(root)); 18 | } catch(IOException ioe) { 19 | ioe.printStackTrace(); 20 | } 21 | 22 | this.stage = stage; 23 | stage.setTitle("FX Mailer"); 24 | stage.show(); 25 | } 26 | 27 | public static void main(String[] args) { 28 | launch(args); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/util/Tools.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer.util; 2 | 3 | import java.io.File; 4 | import java.util.Scanner; 5 | 6 | public class Tools { 7 | 8 | public static String loadTemplateFile(String filename) { 9 | try { 10 | File file = new File(String.format("%s\\%s.txt", Constants.HTML_TEMPLATE_LOCATION, filename, ".txt")); 11 | 12 | StringBuilder fileContents = new StringBuilder((int) file.length()); 13 | 14 | try (Scanner scanner = new Scanner(file)) { 15 | while (scanner.hasNextLine()) { 16 | fileContents.append(scanner.nextLine() + System.lineSeparator()); 17 | } 18 | return fileContents.toString(); 19 | } 20 | } catch (Exception e) { 21 | e.printStackTrace(); 22 | } 23 | 24 | return null; 25 | } 26 | 27 | public static String replaceString(String input, String... replace) { 28 | for(int i = 0; i < replace.length; i++) 29 | input = input.replaceFirst("%s", replace[i]); 30 | 31 | return input; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/engine/TemplateBuilder.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer.engine; 2 | 3 | import com.houarizegai.fxmailer.util.Tools; 4 | 5 | public class TemplateBuilder { 6 | private String header, body, footer; 7 | 8 | public TemplateBuilder setHeader(String imagePath, String title) { 9 | this.header = String.format(Tools.loadTemplateFile("header"), 10 | imagePath == null ? "" : imagePath, 11 | title == null ? "" : title); 12 | 13 | return this; 14 | } 15 | 16 | public TemplateBuilder setBody(String content) { // generate body 17 | this.body = new StringBuilder() 18 | .append(Tools.loadTemplateFile("body-start")) 19 | .append(MarkdownParser.toHtml(content)) 20 | .append(Tools.loadTemplateFile("body-end")) 21 | .toString(); 22 | 23 | return this; 24 | } 25 | 26 | public TemplateBuilder setFooter(String leftContent, String rightContent) { 27 | this.footer = Tools.replaceString(Tools.loadTemplateFile("footer"), 28 | MarkdownParser.toHtml(leftContent), 29 | MarkdownParser.toHtml(rightContent)); 30 | 31 | return this; 32 | } 33 | 34 | public String build() { 35 | return String.valueOf(new StringBuilder().append(Tools.loadTemplateFile("begin")) 36 | .append(header) 37 | .append(body) 38 | .append(footer) 39 | .append(Tools.loadTemplateFile("end"))); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/resources/template/begin.txt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Email Design 6 | 7 | 53 | 54 | 55 |
-------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/util/Constants.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer.util; 2 | 3 | import java.nio.file.Paths; 4 | 5 | public class Constants { 6 | public static final String HTML_TEMPLATE_LOCATION; 7 | 8 | static { // get relative template folder path 9 | HTML_TEMPLATE_LOCATION = new StringBuilder().append(Paths.get("").toAbsolutePath()) 10 | .append("\\src\\main\\resources\\template\\").toString(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/resources/template/footer.txt: -------------------------------------------------------------------------------- 1 | 2 |
56 | 57 |
58 | 59 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FXMailer 2 | Desktop application Tool. Allow you to send a beautiful html template to multiple email recipients with one click! 3 | 4 | [![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](LICENSE) 5 | ![java 8 badge](https://img.shields.io/badge/Java-8-red.svg) 6 | ![Open Source Love](https://badges.frapsoft.com/os/v1/open-source.svg?v=102) 7 | 8 | ## Features 9 | * [x] Easy to use 10 | * [x] Send HTML template with images 11 | * [x] Send Email to multiple receivers 12 | * [x] Can Inject the name of receiver in template using this tag: \ 13 | * [x] Parse JSON data (email + name of each recipient) 14 | * [x] Support Markdown syntax (We convert Markdown to HTML template) 15 | 16 | # Thank _You_! 17 | Please :star: this repo and share it with others 18 | 19 | ## Screenshoots 20 | Main App | 21 | |:---------------------:| 22 | ![screenshoot](screenshots/fxmailer_main.png) | 23 | Sending Status | 24 | ![screenshot](screenshots/fxmailer_status.png) | 25 | Template (result) | 26 | ![screenshot](screenshots/template_sample.png) | 27 | 28 | ## Requirements 29 | * Java version 8 (JDK 8) 30 | * Maven 31 | * Internet connection 32 | * Sender Email must be Gmail 33 | * Allowing less secure apps to access your account ([Learn more](https://support.google.com/accounts/answer/6010255?hl=en)) 34 | 35 | ## Libraries used 36 | * JFoenix (Material design) 37 | * FlexMark (Markdown Parser) 38 | * Gson (JSON parser) 39 | * Java Mail 40 | 41 | ## Technologies used 42 | * JavaFX 43 | 44 | ## Installation 45 | 1. Download the repository files (project) from the download section or clone this project by typing in the bash the following command: 46 | 47 | git clone https://github.com/HouariZegai/FXMailer.git 48 | 2. Import it in Intellij IDEA or any other Java IDE and let Maven download the libraries used for you. 49 | 3. Run the application :D 50 | 51 | ## Recipients JSON format (Sample) 52 | 53 | [ 54 | { 55 | "name": "Houari Zegai", 56 | "email": "admin@houarizegai.net" 57 | }, 58 | { 59 | "name": "Mohamed Ali", 60 | "email": "mohamed@houarizegai.net" 61 | } 62 | ] 63 | 64 | ## Contributing 💡 65 | If you want to contribute to this project and make it better with new ideas, your pull request is very welcomed. 66 | If you find any issue just put it in the repository issue section, thank you. 67 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | com.houarizegai 8 | fxmailer 9 | 1.0-SNAPSHOT 10 | jar 11 | 12 | 13 | 1.8 14 | 1.8 15 | 16 | 17 | 18 | 19 | com.jfoenix 20 | jfoenix 21 | 8.0.4 22 | 23 | 24 | 25 | com.vladsch.flexmark 26 | flexmark-all 27 | 0.50.44 28 | 29 | 30 | 31 | org.apache.commons 32 | commons-email 33 | 1.5 34 | 35 | 36 | 37 | javax.mail 38 | javax.mail-api 39 | 1.6.2 40 | 41 | 42 | 43 | com.google.code.gson 44 | gson 45 | 2.8.9 46 | compile 47 | 48 | 49 | 50 | 51 | 52 | 53 | org.apache.maven.plugins 54 | maven-assembly-plugin 55 | 56 | 57 | package 58 | 59 | single 60 | 61 | 62 | 63 | 64 | 65 | com.houarizegai.fxmailer.App 66 | 67 | 68 | 69 | 70 | jar-with-dependencies 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | -------------------------------------------------------------------------------- /src/main/resources/css/main.css: -------------------------------------------------------------------------------- 1 | * { 2 | -fx-font-family: Tahoma; 3 | 4 | -base: #2196f3; 5 | -primary: #4285f4; 6 | -info: #33B5E5; 7 | -success: #02C852; 8 | -warning: #FF8800; 9 | -danger: #FF3547; 10 | -default: #666; 11 | 12 | -base-color: #2196f3; 13 | -bg-color: #FFF 14 | } 15 | 16 | .root { 17 | -fx-padding: 10px; 18 | -fx-spacing: 15 19 | } 20 | 21 | .container { 22 | -fx-padding: 10px; 23 | -fx-background-color: -bg-color; 24 | -fx-effect: dropshadow(three-pass-box, rgba(0, 0, 0, 0.1), 6, 0, 0, 0); 25 | -fx-background-radius: 10; 26 | -fx-spacing: 10 27 | } 28 | 29 | .card { 30 | -fx-padding: 15px; 31 | -fx-background-color: -bg-color; 32 | -fx-effect: dropshadow(three-pass-box, rgba(0,0,0,0.2), 6, 0, 0, 0); 33 | -fx-background-radius: 10; 34 | -fx-spacing: 15 35 | } 36 | 37 | .title { 38 | -fx-font-size: 24px; 39 | -fx-text-fill: linear-gradient(from 0% 0% to 100% 200%, repeat, -base 0%, -primary 50%); 40 | } 41 | 42 | .sub-title { 43 | -fx-font-size: 16px; 44 | -fx-text-fill: -base-color; 45 | } 46 | 47 | .card-title { 48 | -fx-font-size: 14px; 49 | -fx-text-fill: -base-color; 50 | } 51 | 52 | .txt { 53 | -fx-font-size: 13px; 54 | -fx-text-fill: #777; 55 | } 56 | 57 | .area { 58 | -fx-pref-width: 250px; 59 | -fx-pref-height: 240px; 60 | -fx-font-size: 14px; 61 | -jfx-unfocus-color: #999; 62 | -jfx-focus-color: -base-color; 63 | -fx-prompt-text-fill: #888; 64 | } 65 | 66 | .field { 67 | -fx-pref-width: 250px; 68 | -fx-pref-height: 30px; 69 | -fx-font-size: 14px; 70 | -jfx-label-float: true; 71 | -jfx-unfocus-color: #999; 72 | -jfx-focus-color: -base-color; 73 | -fx-prompt-text-fill: #888; 74 | } 75 | 76 | .field-info { 77 | 78 | } 79 | 80 | .combo { 81 | -fx-font-size: 14px; 82 | -jfx-label-float: true; 83 | -jfx-unfocus-color: #999; 84 | -jfx-focus-color: -base-color; 85 | -fx-prompt-text-fill: #888; 86 | -fx-cursor: hand; 87 | } 88 | 89 | .btn { 90 | -fx-pref-width: 80px; 91 | -fx-pref-height: 35px; 92 | -fx-background-radius: 5; 93 | -fx-font-size: 15px; 94 | -jfx-button-type: RAISED; 95 | -fx-cursor: hand; 96 | } 97 | 98 | .btn-primary { 99 | -fx-text-fill: #FFF; 100 | -fx-background-color: -primary; 101 | } 102 | 103 | .btn-info { 104 | -fx-text-fill: #FFF; 105 | -fx-background-color: -info; 106 | } 107 | 108 | .btn-success { 109 | -fx-text-fill: #FFF; 110 | -fx-background-color: -success; 111 | } 112 | 113 | .btn-warning { 114 | -fx-text-fill: #FFF; 115 | -fx-background-color: -warning; 116 | } 117 | 118 | .btn-danger { 119 | -fx-text-fill: #FFF; 120 | -fx-background-color: -danger; 121 | } 122 | 123 | .btn-load { 124 | -fx-pref-width: 60px; 125 | -fx-pref-height: 30px; 126 | -fx-font-size: 14px; 127 | } 128 | 129 | .sending-container { 130 | -fx-background-color: rgba(0, 0, 0, 0.1); 131 | } 132 | 133 | .progress { 134 | -fx-pref-height: 15px; 135 | } 136 | 137 | .lbl-sending-progress { 138 | -fx-font-size: 22px; 139 | } 140 | 141 | .lbl-success { 142 | -fx-text-fill: -success; 143 | } 144 | 145 | .lbl-danger { 146 | -fx-text-fill: -danger; 147 | } -------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/engine/EmailEngine.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer.engine; 2 | 3 | import javafx.application.Platform; 4 | 5 | import javax.activation.DataHandler; 6 | import javax.activation.DataSource; 7 | import javax.activation.FileDataSource; 8 | import javax.mail.*; 9 | import javax.mail.internet.InternetAddress; 10 | import javax.mail.internet.MimeBodyPart; 11 | import javax.mail.internet.MimeMessage; 12 | import javax.mail.internet.MimeMultipart; 13 | import java.util.Properties; 14 | import java.util.concurrent.Semaphore; 15 | 16 | public class EmailEngine { 17 | private Properties props; 18 | private Session session; 19 | private Message message; 20 | 21 | private MimeMultipart multipart; 22 | private BodyPart messageBodyPart; 23 | 24 | public EmailEngine() { 25 | props = new Properties(); 26 | props.put("mail.smtp.auth", "true"); 27 | props.put("mail.smtp.starttls.enable", "true"); 28 | props.put("mail.smtp.host", "smtp.gmail.com"); 29 | props.put("mail.smtp.port", "587"); 30 | 31 | // This mail has 2 part, the BODY and the embedded image 32 | multipart = new MimeMultipart("related"); 33 | } 34 | 35 | public EmailEngine setAuth(String email, String password) { 36 | session = Session.getInstance(props, 37 | new javax.mail.Authenticator() { 38 | protected PasswordAuthentication getPasswordAuthentication() { 39 | return new PasswordAuthentication(email, password); 40 | } 41 | }); 42 | 43 | // Create a default MimeMessage object. 44 | message = new MimeMessage(session); 45 | 46 | // Set From: header field of the header. 47 | try { 48 | message.setFrom(new InternetAddress(email)); 49 | } catch (MessagingException e) { 50 | e.printStackTrace(); 51 | } 52 | 53 | return this; 54 | } 55 | 56 | public EmailEngine setSubject(String subject) { 57 | // Set Subject: header field 58 | try { 59 | message.setSubject(subject); 60 | } catch (MessagingException e) { 61 | e.printStackTrace(); 62 | } 63 | 64 | return this; 65 | } 66 | 67 | public EmailEngine setContent(String htmlContent) { 68 | // first part (the html) 69 | messageBodyPart = new MimeBodyPart(); 70 | try { 71 | messageBodyPart.setContent(htmlContent, "text/html"); 72 | // add it 73 | multipart.addBodyPart(messageBodyPart); 74 | } catch (MessagingException e) { 75 | e.printStackTrace(); 76 | } 77 | 78 | return this; 79 | } 80 | 81 | public EmailEngine setHeaderImage(String path) { 82 | // second part (the image) 83 | messageBodyPart = new MimeBodyPart(); 84 | DataSource fds = new FileDataSource(path); 85 | 86 | try { 87 | messageBodyPart.setDataHandler(new DataHandler(fds)); 88 | messageBodyPart.setHeader("Content-ID", ""); 89 | 90 | // add image to the multipart 91 | multipart.addBodyPart(messageBodyPart); 92 | } catch (MessagingException e) { 93 | e.printStackTrace(); 94 | } 95 | 96 | return this; 97 | } 98 | 99 | public boolean send(String recipient) { 100 | try { 101 | // Set To: header field of the header. 102 | message.setRecipients(Message.RecipientType.TO, InternetAddress.parse(recipient)); 103 | 104 | // put everything together 105 | message.setContent(multipart); 106 | 107 | // Send message 108 | Transport.send(message); 109 | 110 | return true; // successful send it 111 | } catch (MessagingException e) { 112 | throw new RuntimeException(e); 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /src/main/java/com/houarizegai/fxmailer/controller/MainController.java: -------------------------------------------------------------------------------- 1 | package com.houarizegai.fxmailer.controller; 2 | 3 | import com.google.gson.Gson; 4 | import com.google.gson.reflect.TypeToken; 5 | import com.houarizegai.fxmailer.App; 6 | import com.houarizegai.fxmailer.engine.EmailEngine; 7 | import com.houarizegai.fxmailer.engine.TemplateBuilder; 8 | import com.houarizegai.fxmailer.model.Receiver; 9 | import com.jfoenix.controls.*; 10 | import javafx.application.Platform; 11 | import javafx.fxml.FXML; 12 | import javafx.fxml.Initializable; 13 | import javafx.scene.control.Label; 14 | import javafx.scene.layout.StackPane; 15 | import javafx.scene.web.WebView; 16 | import javafx.stage.FileChooser; 17 | 18 | import java.io.File; 19 | import java.net.URL; 20 | import java.util.List; 21 | import java.util.ResourceBundle; 22 | 23 | public class MainController implements Initializable { 24 | 25 | @FXML 26 | private JFXTextField fieldSubject, fieldSenderEmail; 27 | @FXML 28 | private JFXPasswordField fieldSenderPassword; 29 | 30 | @FXML 31 | private JFXComboBox comboRecevicesFormatType; 32 | @FXML 33 | private JFXTextArea areaTo; 34 | 35 | @FXML 36 | private JFXTextField fieldHeaderTitle; 37 | @FXML 38 | private Label lblHeaderImgName; 39 | 40 | @FXML 41 | private JFXTextArea areaBody; 42 | 43 | @FXML 44 | private JFXTextField fieldFooterAbout; 45 | @FXML 46 | private JFXTextArea areaFooterContact; 47 | 48 | @FXML 49 | private WebView webViewTemplate; 50 | 51 | private File headerImg; 52 | 53 | private FileChooser imgChooser; 54 | 55 | private String htmlTemplate; 56 | 57 | /* Start sending status */ 58 | 59 | @FXML 60 | private StackPane stackSendingContainer; 61 | 62 | @FXML 63 | private Label lblNumberOfSent, lblNumberOfReceivers, lblNumberOfSuccess, lblNumberOfFailed; 64 | 65 | @FXML 66 | private JFXProgressBar progressSending; 67 | 68 | @FXML 69 | private JFXButton btnDone; 70 | 71 | /* End sending status */ 72 | 73 | @Override 74 | public void initialize(URL location, ResourceBundle resources) { 75 | // init combobox 76 | comboRecevicesFormatType.getItems().add("JSON"); 77 | comboRecevicesFormatType.getSelectionModel().selectFirst(); 78 | 79 | // init image chooser 80 | imgChooser = new FileChooser(); 81 | FileChooser.ExtensionFilter imgChooserExtension = new FileChooser.ExtensionFilter("Image", "*.png", "*.jpg", "*.jpeg", "*.gif"); 82 | imgChooser.getExtensionFilters().add(imgChooserExtension); 83 | } 84 | 85 | @FXML 86 | private void onLoadHeaderImage() { 87 | headerImg = imgChooser.showOpenDialog(App.stage); 88 | if(headerImg != null) 89 | lblHeaderImgName.setText(headerImg.getName()); 90 | } 91 | 92 | @FXML 93 | private void onPreview() { 94 | htmlTemplate = new TemplateBuilder() 95 | .setHeader(headerImg == null ? "" : headerImg.getPath(), fieldHeaderTitle.getText()) 96 | .setBody(areaBody.getText()) 97 | .setFooter(fieldFooterAbout.getText(), areaFooterContact.getText()) 98 | .build(); 99 | 100 | webViewTemplate.getEngine().loadContent(htmlTemplate); 101 | } 102 | 103 | @FXML 104 | private void onSend() { 105 | TemplateBuilder templateBuilder = new TemplateBuilder() 106 | .setHeader("cid:headerImage", fieldHeaderTitle.getText()) 107 | .setFooter(fieldFooterAbout.getText(), areaFooterContact.getText()); 108 | 109 | EmailEngine emailEngine = new EmailEngine() 110 | .setAuth(fieldSenderEmail.getText().trim(), fieldSenderPassword.getText()) 111 | .setSubject(fieldSubject.getText()); 112 | 113 | if("JSON".equalsIgnoreCase(comboRecevicesFormatType.getSelectionModel().getSelectedItem())) { 114 | stackSendingContainer.setVisible(true); 115 | 116 | Gson gson = new Gson(); 117 | List receivers = gson.fromJson(areaTo.getText().trim(), new TypeToken>(){}.getType()); 118 | 119 | clearSendingStatus(); 120 | int numberOfReceivers = receivers.size(); 121 | lblNumberOfReceivers.setText(String.valueOf(numberOfReceivers)); 122 | 123 | new Thread(()-> 124 | Platform.runLater(() -> { 125 | int numberOfSent = 0; 126 | for(Receiver receiver : receivers) { 127 | templateBuilder.setBody(areaBody.getText() 128 | .replaceFirst("", "" + receiver.getName() + "") 129 | .replace("", receiver.getName())); 130 | 131 | // init email engine 132 | emailEngine.setContent(templateBuilder.build()) 133 | .setHeaderImage(headerImg.getPath()); 134 | 135 | boolean isSent = emailEngine.send(receiver.getEmail()); 136 | numberOfSent++; 137 | if (isSent) { 138 | System.out.println(String.format("%s -> Success [%d/%d]", receiver.getEmail(), numberOfSent, numberOfReceivers)); 139 | lblNumberOfSuccess.setText(String.valueOf(Integer.parseInt(lblNumberOfSuccess.getText()) + 1)); 140 | } else { 141 | System.out.println(String.format("%s -> Failed [%d/%d]", receiver.getEmail(), numberOfSent, numberOfReceivers)); 142 | lblNumberOfFailed.setText(String.valueOf(Integer.parseInt(lblNumberOfFailed.getText()) + 1)); 143 | } 144 | 145 | lblNumberOfSent.setText(String.valueOf(Integer.valueOf(lblNumberOfSent.getText()) + 1)); 146 | progressSending.setProgress(Integer.valueOf(lblNumberOfSent.getText()) / (double) numberOfReceivers); 147 | 148 | btnDone.setDisable(false); 149 | } 150 | }) 151 | ).start(); 152 | } 153 | 154 | } 155 | 156 | private void clearSendingStatus() { 157 | lblNumberOfSent.setText("0"); 158 | lblNumberOfReceivers.setText(null); 159 | lblNumberOfSuccess.setText("0"); 160 | lblNumberOfFailed.setText("0"); 161 | progressSending.setProgress(0d); 162 | btnDone.setDisable(true); 163 | } 164 | 165 | /* sending status actions */ 166 | 167 | @FXML 168 | private void onDone() { 169 | stackSendingContainer.setVisible(false); 170 | } 171 | 172 | } 173 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /src/main/resources/fxml/Main.fxml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 214 | 215 | 216 | 217 | 218 | --------------------------------------------------------------------------------