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 from
und password
fehlen, verwende ich einen Standardabsender und ein Standardkennwort, z . B. noreply@bar.com
und 123456
.
Wenn der Benutzer das from
Argument übergibt , muss er auch das password
Argument ü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");
}
From
E-Mail-Adresse ist nicht immer der SMTP-Authentifizierungsname.