Main Menu

Senin, April 13, 2009

Java : Send email with attachment

sometime we need to add attachment in our mail. in java we can MimeMessageHelper to add attachment in our mail.. this is the example code.

JavaMailSenderImpl sender = new JavaMailSenderImpl();

MimeMessage message = sender.createMimeMessage();

// use the true flag to indicate you need a multipart message
MimeMessageHelper helper = new MimeMessageHelper(message, true);

helper.setText("Check out this image!");

// let's attach the infamous windows Sample file (this time copied to c:/)
FileSystemResource file = new FileSystemResource(new File("c:/Sample.jpg"));
helper.addAttachment("CoolImage.jpg", file);


0 komentar: