All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.thematchbox.email.TestSendMail Maven / Gradle / Ivy

Go to download

This project contains some common utilities used in different projects from theMatchBox.

There is a newer version: 2.0.2
Show newest version
package com.thematchbox.email;

import javax.mail.MessagingException;
import java.io.IOException;

public class TestSendMail {
    public static void main(String[] args) {

        String host = null;
        String user = null;
        String password = null;
        int port = 25;
        boolean useTls = false;
        boolean authenticate = false;
        String toAddress = null;

        int i = 0;
        while (i < args.length) {
            String arg = args[i];
            switch (arg) {
                case "-h":
                case "--host":
                    i++;
                    if (i < args.length) {
                        host = args[i];
                    }
                    break;
                case "-p":
                case "--port":
                    i++;
                    if (i < args.length) {
                        port = Integer.parseInt(args[i]);
                    }
                    break;
                case "-u":
                case "--user":
                    i++;
                    if (i < args.length) {
                        user = args[i];
                    }
                    break;
                case "-P":
                case "--password":
                    i++;
                    if (i < args.length) {
                        password = args[i];
                    }
                    break;
                case "-tls":
                case "--useTls":
                    useTls = true;
                    break;
                case "-auth":
                case "--authenticate":
                    authenticate = true;
                    break;
                case "-t":
                case "--to":
                    i++;
                    if (i < args.length) {
                        toAddress = args[i];
                    }
                    break;
                default:
                    break;
            }
            i++;
        }

        SendMail sendMail = new SendMail(user, password, host, port, useTls, authenticate);
        try {
            sendMail.sendSimpleMail(toAddress, toAddress, "", "", "TestMail", "TestContent");
        } catch (IOException | MessagingException e) {
            e.printStackTrace();
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy