in commons-email2-jakarta/src/main/java/org/apache/commons/mail2/jakarta/MultiPartEmail.java [197:217]
public MultiPartEmail attach(final EmailAttachment attachment) throws EmailException {
EmailException.checkNonNull(attachment, () -> "Invalid attachment.");
MultiPartEmail result = null;
final URL url = attachment.getURL();
if (url == null) {
String fileName = null;
try {
fileName = attachment.getPath();
final File file = new File(fileName);
if (!file.exists()) {
throw new IOException("\"" + fileName + "\" does not exist");
}
result = attach(new FileDataSource(file), attachment.getName(), attachment.getDescription(), attachment.getDisposition());
} catch (final IOException e) {
throw new EmailException("Cannot attach file \"" + fileName + "\"", e);
}
} else {
result = attach(url, attachment.getName(), attachment.getDescription(), attachment.getDisposition());
}
return result;
}