Ich habe Spring Boot verwendet, um ein Shell-Projekt zu entwickeln, mit dem E-Mails gesendet werden, z
sendmail -from foo@bar.com -password foobar -subject "hello world" -to aaa@bbb.com
Wenn die Argumente fromund passwordfehlen, verwende ich einen Standardabsender und ein Standardkennwort, z . B. noreply@bar.comund 123456.
Wenn der Benutzer das fromArgument übergibt , muss er auch das passwordArgument übergeben und umgekehrt. Das heißt, entweder sind beide nicht null oder beide sind null.
Wie überprüfe ich das elegant?
Jetzt ist mein Weg
if ((from != null && password == null) || (from == null && password != null)) {
throw new RuntimeException("from and password either both exist or both not exist");
}
FromE-Mail-Adresse ist nicht immer der SMTP-Authentifizierungsname.