I have Modifiy my code and now I am sending an inline image with the content id in which random Unique id will be generated and stored in database.
SMTPMessage message = new SMTPMessage(session);
MimeMultipart content = new MimeMultipart("related");
String cid = UUID.randomUUID().toString();
MimeBodyPart textPart = new MimeBodyPart();
message.setFrom(new InternetAddress(user));
InternetAddress[] recipientAddress = new InternetAddress[recipientList.length];
int counter = 0;
for (String recipient : recipientList) {
recipientAddress[counter] = new InternetAddress(recipient.trim());
counter++;
}
message.setRecipients(Message.RecipientType.BCC, recipientAddress);
message.setReplyTo(new InternetAddress[]{new InternetAddress("[email protected]")});
message.setSubject("News Letters");
textPart.addHeader("Disposition-Notification-To", "[email protected]");
textPart.setContent("<html>" + body + "</html>", "text/html");
MimeBodyPart imagePart = new MimeBodyPart();
imagePart.setContentID("<img src='teapot.jpg?'" + cid + " width='1px' height='1px'>");
imagePart.attachFile("C:\\Users\\TANISHA AGARWAL\\Documents\\NetBeansProjects\\EmailMarketing\\build\\web\\resources\\teapot.jpg");
imagePart.setDisposition(MimeBodyPart.INLINE);
imagePart.setHeader("Content-Id", cid);
LOG.info("=========================================" + textPart.getContentID());
content.addBodyPart(textPart);
content.addBodyPart(imagePart);
message.setContent(content);
Transport.send(message);
String Status;
int Delievered;
int opened;
int clicked;
int counters = 0;
LOG.info("Notify Message is :" + SMTPMessage.NOTIFY_SUCCESS);
if (SMTPMessage.NOTIFY_SUCCESS == 1) {
Status = "Sent";
Delievered = 1;
opened = 0;
clicked = 0;
// for (int i = 0; i > counters; i++) {
// Delievered = i;
// LOG.info("Delievered: " + Delievered);
// counters++;
// }
} else {
LOG.info("------------------------------------");
Status = "Failed";
Delievered = 0;
opened = 0;
clicked = 0;
}
I have made a column name open in my database which is initially set to 0 but when user open the mail I want that it should be updated to how many times user has open the mail.
Please help.
You need a web application that handles the requests for the hidden image, extracts information from the URL about the original message, and updates the database.
Note that some mailers won't display such images by default so this method is only an approximation at best.