我用spring boot开发了一个用于发送电子邮件的shell项目,例如
sendmail -from foo@bar.com -password foobar -subject "hello world" -to aaa@bbb.com
如果缺少from和password参数,则使用默认的发送者和密码,例如noreply@bar.com和123456。
因此,如果用户传递了from参数,他们也必须传递password参数,反之亦然。也就是说,两者都不为空,或者两者都不为空。
如何优雅地检查?
现在我的方式是
if ((from != null && password == null) || (from == null && password != null)) {
throw new RuntimeException("from and password either both exist or both not exist");
}
From电子邮件地址并不总是SMTP验证名称。