com.thematchbox.email.TestSendMail Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of TheMatchBox-Common Show documentation
Show all versions of TheMatchBox-Common Show documentation
This project contains some common utilities used in different projects from theMatchBox.
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();
}
}
}