简体   繁体   中英

Attachment Coming while sending meeting invite on lotus notes

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());
    }

}

private byte[] createICalInvitation(String _meetingID, String _subject,
        String _content, Date _start, Date _end, TimeZone _tz,
        String mailToAddress, boolean isMeetingInvite,
        List<String> existingAttendeeList) throws Exception {
    CompatibilityHints.setHintEnabled(
            CompatibilityHints.KEY_OUTLOOK_COMPATIBILITY, true);
    DateTime start = new DateTime(_start);
    DateTime end = new DateTime(_end);
    VEvent vEvent = new VEvent(start, end, _subject);
    vEvent.getProperties().add(new Uid(_meetingID));
    vEvent.getProperties().add(new Description(_content));
    vEvent.getProperties().add(new XProperty("X-LOTUS-BROADCAST", "false"));
    Attendee dev = new Attendee(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(
                    "//Lotus Development Corporation//NONSGML Notes 8.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);
    }
    TimeZoneRegistry registry = TimeZoneRegistryFactory.getInstance()
            .createRegistry();
    VTimeZone tz = registry.getTimeZone(_tz.getID()).getVTimeZone();
    cal.getComponents().add(tz);
    cal.getComponents().add(vEvent);
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    CalendarOutputter outputter = new CalendarOutputter();
    outputter.output(cal, bout);
    return bout.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);

}

You're sending a multipart message with only one body part. Most mail readers are going to assume the first text (plain or html) body is the main body and the rest are attachments. Your message has no main text body part, so the mail reader is likely assuming that the body part you sent is an attachment.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM