I would like to know what I am doing wrong here (what I am missing). My email does get sent out but without the attachment. The file I am sending is simply called "log". As you will see I am trying multiple things here, I have also tried them one by one, but none of them are working:
MimeMessage message = new MimeMessage(session);
MimeBodyPart emailAttachment = new MimeBodyPart();
Multipart multipart = new MimeMultipart();
int len = build.getLogFile().getPath().length();
//I have verified that "file" provides the right path
String file = build.getLogFile().getPath().substring(0, (len-3));
String fileName = "log";
DataSource source = new FileDataSource(file);
emailAttachment.setDataHandler(new DataHandler(source));
//I know this .attachFile is not needed but I added it when nothing was working
emailAttachment.attachFile(build.getLogFile());
emailAttachment.setFileName(fileName);
multipart.addBodyPart(emailAttachment);
message.setContent(multipart);
message.setFrom(adminAddress);
message.setText(builder.toString());
message.setSentDate(new Date());
mailSender.send(message);
Thanks