Check out the link(my answer to that question) for email sending utility code. You've got to add few line of code to send mail with attachment.
On submit the information should come to email
In EmailUtility.java after
msg.setSentDate(new Date());
comment
msg.setText(message);
And add the following code:
// creates message part
MimeBodyPart messageBodyPart = new MimeBodyPart();
messageBodyPart.setContent(message, "text/html");
String attachFile = "C:/imgname.jpg";
// creates multi-part
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(messageBodyPart);
// adds attachments
if(reason.equals("attach"))
if (attachFile != null) {
MimeBodyPart attachPart = new MimeBodyPart();
attachPart.attachFile(attachFile);
multipart.addBodyPart(attachPart);
}
// sets the multi-part as e-mail's content
msg.setContent(multipart);
You've got to change C:/imgname.jpg to your file name along with its path.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…