Cách gửi Email có định dạng Ảnh+ HTML trong JAVA (dùng Velocity?

Có anh chị em nào đã làm về Java, Velicity không ạ???
Đầu tiên, nếu mình chỉ dùng Template HTML thì ok, người nhận, nhận được mail, Xem được luôn, mà không phải tải gì hết.
Nhưng khi mình muốn kết hợp thêm Ảnh + Template HTML (Ảnh xuất hiện vị trí Header Nội dung Mail)
Thì nó lại xuất hiện dưới dạng ra thành 2 file đính kèm vào Mail người nhận.(1 file Ảnh + 1 file HTML)???
Vậy Mình phải làm sao để 2 file Ảnh + HTML kết hợp thành 1 file duy nhất (Ảnh ở trên cùng), để người nhận có thể đọc được nội dung luôn mà không cần tải file về rồi mới xem được ??
Code của mình đây:


public class SendEmailVelocity {
	public static void main(String[] args) {

		final String username = Contants.myEmail;
		final String password = Contants.myPass;
		final String toMailRecipient = Contants.mailRecipient;

		Properties props = new Properties();
		props.put("mail.smtp.auth", "true");
		props.put("mail.smtp.starttls.enable", "true");
		props.put("mail.smtp.host", "smtp.gmail.com");
		props.put("mail.smtp.port", "587");

		Session session = Session.getInstance(props,
				new javax.mail.Authenticator() {
					protected PasswordAuthentication getPasswordAuthentication() {
						return new PasswordAuthentication(username, password);
					}
				});

		try {
			
			Template template = Velocity.getTemplate("helloworld.vm");
			  VelocityContext context = new VelocityContext();
			  context.put("name", "ABC123");
			StringWriter message = new StringWriter();
			  template.merge(context, message);
			 
			
			MimeMultipart multipart = new MimeMultipart("related");
			
			  BodyPart imageBodyPart = new MimeBodyPart();
			  
			  StringBuffer imgPath = new StringBuffer().append(File.separator).append("D:\\Temp\\data\\logo.gif");
			  
			  DataSource fds = new FileDataSource(imgPath.toString());
			  imageBodyPart.setDataHandler(new DataHandler(fds));
			  
			  imageBodyPart.setHeader("Content-ID","<imageID>");
			
			  multipart.addBodyPart(imageBodyPart);
			  
			  BodyPart messageBodyPart = new MimeBodyPart();
			  
			  StringBuffer messageBuffer = new StringBuffer();
			  messageBuffer.append(message.toString());
			  messageBuffer.append("<img src='cid:imageID\'>");
			  
			  messageBodyPart.setContent(messageBuffer.toString(), "text/html");
			  multipart.addBodyPart(messageBodyPart);
			  
			  Message msg = new MimeMessage(session);
			  
			  msg.setContent(multipart);
			  msg.addRecipients(Message.RecipientType.TO, InternetAddress.parse(toMailRecipient));
			  
			  msg.setSubject("Test Email Velocity ");
			  msg.setSentDate(new Date());
			  msg.setFrom(new InternetAddress("[email protected]"));
			  
			  Transport transport = session.getTransport("smtp");
			  transport.connect(props.getProperty("connectHost"), props.getProperty("connectUser"),props.getProperty("connectPassword"));
			  
			  transport.sendMessage(msg,msg.getAllRecipients());
			  transport.close();
			  System.out.println("Sent!!!");
			  
		} catch (MessagingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}

Mình làm theo Link code hướng dẫn thư viện Vilocity tại đây:
http://sengopal.github.io/blog/blog/java-mail-using-velocity-templates.html

Có anh chị em nào làm về Java Mail [ Velocity] ? thì xem hộ mình với ạ?

83% thành viên diễn đàn không hỏi bài tập, còn bạn thì sao?