I am trying to send a meeting invite on Lotus notes using iCalendar and Java Mail API and its working fine except the fact that in the content of the mail an attachment is coming which doesn't even open. I have checked my code and can confirm that no such attachment is included from the code end. Can someone explain me why this is happening? Here is my piece of code:
public void postMail(String meetingId, List<String> ToList,
List<String> existingAttendeeList, String subject, String message,
Date startDate, Date endDate, String from, boolean isMeetingInvite)
throws UtilException {
String[] recipients = null;
if ((ToList == null || ToList.size() == 0)) {
log.error("Both recipients and recipientCC are null");
throw new UtilException("Both recipients and recipientCC are null");
} else {
recipients = new String[ToList.size()];
recipients = (String[]) ToList.toArray(recipients);
}
boolean debug = false;
Properties props = new Properties();
props.put("mail.smtp.host", SMTP_HOST_NAME);
props.put("mail.smtp.auth", "false");
Authenticator auth = new SMTPAuthenticator();
Session session = Session.getInstance(props, auth);
session.setDebug(debug);
MimeMessage mimeMessage = new MimeMessage(session);
InternetAddress addressFrom = new InternetAddress(from);
mimeMessage.setFrom(addressFrom);
if (!(recipients == null)) {
InternetAddress[] addressTo = new InternetAddress[recipients.length];
for (int i = 0; i < recipients.length; i++) {
addressTo[i] = new InternetAddress(recipients[i]);
}
mimeMessage.setRecipients(Message.RecipientType.TO, addressTo);
}
Multipart multipart = new MimeMultipart();
MimeBodyPart iCalAttachment = new MimeBodyPart();
TimeZone tz = TimeZone.getDefault();
byte[] invite = createICalInvitation(meetingId, subject, message,
startDate, endDate, tz, from, isMeetingInvite,
existingAttendeeList);
iCalAttachment.setDataHandler(new DataHandler(
new ByteArrayDataSource(new ByteArrayInputStream(invite),
"text/calendar;method=REQUEST;charset=\"UTF-8\"")));
multipart.addBodyPart(iCalAttachment);
mimeMessage.setContent(multipart);
Transport.send(mimeMessage);
} throw new UtilException(e.toString());
}
String_content,Date_start,Date_end,TimeZone_tz,StringmailToAddress,booleanisMeetingInvite,List<String>existingAttendeeList)throwsException{CompatibilityHints.setHintEnabled(CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY,true);DateTimestart=newDateTime(_start);DateTimeend=newDateTime(_end);VEventvEvent=newVEvent(start,end,_subject);vEvent.getProperties().add(newUid(_meetingID));vEvent.getProperties().add(newDescription(_content));vEvent.getProperties().add(newXProperty("X-LOTUS-BROADCAST","false"));Attendeedev=newAttendee(URI.create("mailto:" + mailToAddress));vEvent.getProperties().add(dev);Organizer organizer = new Organizer(URI.create(mailToAddress));vEvent.getProperties().add(organizer);if (existingAttendeeList != null && existingAttendeeList.size() != 0) { for (String index : existingAttendeeList) { Attendee existingAttendee = new Attendee(index); vEvent.getProperties().add(existingAttendee); }}net.fortuna.ical4j.model.Calendar cal = new net.fortuna.ical4j.model.Calendar();cal.getProperties() .add(new ProdId( "//LotusDevelopmentCorporation//NONSGMLNotes8.5.2//EN_C"));cal.getProperties().add(net.fortuna.ical4j.model.property.Version.VERSION_2_0);cal.getProperties().add(CalScale.GREGORIAN);if(isMeetingInvite){cal.getProperties().add(net.fortuna.ical4j.model.property.Method.REQUEST);}else{cal.getProperties().add(net.fortuna.ical4j.model.property.Method.CANCEL);}TimeZoneRegistryregistry=TimeZoneRegistryFactory.getInstance().createRegistry();VTimeZonetz=registry.getTimeZone(_tz.getID()).getVTimeZone();cal.getComponents().add(tz);cal.getComponents().add(vEvent);ByteArrayOutputStreambout=newByteArrayOutputStream();CalendarOutputteroutputter=newCalendarOutputter();outputter.output(cal,bout);returnbout.toByteArray();
}
Below is the main method from which I am running this code:
public static void main(String[] args) {
List a = new ArrayList();
a.add("smtp.test2@abc.net");
Calendar c = Calendar.getInstance();
c.roll(Calendar.DATE, 5);
Date d1 = c.getTime();
c.add(Calendar.HOUR, 1);
Date d2 = c.getTime();
SendMail s = new SendMail();
String id = "" + System.currentTimeMillis();
try {
s.postMail("212", a, null, "Hel22lo", "hel22lo", d1, d2,
"smtp.test@abc.net", true);
}
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am trying to send a meeting invite on Lotus notes using iCalendar and Java Mail API and its working fine except the fact that in the content of the mail an attachment is coming which doesn't even open. I have checked my code and can confirm that no such attachment is included from the code end. Can someone explain me why this is happening? Here is my piece of code:
public void postMail(String meetingId, List<String> ToList,
}
private byte[] createICalInvitation(String _meetingID, String _subject,
}
Below is the main method from which I am running this code:
public static void main(String[] args) {
}