I am sending a mail with a attachment, But when i am try to open the file, it's not opening and giving following error:
I try to do it like:
JavaMailSenderImpl mailSender = getMailSender();
MimeMessage message = mailSender.createMimeMessage();
MimeMessageHelper helper;
URLDataSource url;
try {
helper = new MimeMessageHelper(message, true);
url = new URLDataSource(new URL("localhost:8080/test/attachment/simpldoc.docx"));
helper.setFrom(mailFrom);
helper.setSubject(subject);
helper.setTo(mailTo);
helper.setText(text, true);
helper.addAttachment(attachmentName, url);
mailSender.send(message);
}
catch (MessagingException e) {
e.printStackTrace();
}