如何从Gmail Ical4j API发送会议邀请

时间:2013-09-10 06:50:23

标签: java gmail ical4j

我正在使用Ical4j API从我的Gmail帐号发送会议邀请但是如何设置

VEvent meeting = new VEvent(startDt, dur, subject);

VEvent反对邮件API类

    Message message = new MimeMessage(session);
    message.setFrom(new InternetAddress("myemail82@gmail.com"));
    message.setRecipients(Message.RecipientType.TO,    InternetAddress.parse("recepent@gmail.com"));
    message.setSubject("Testing Subject");
    message.setText("Dear Mail Crawler," + "\n\n No spam to my email, please!");
    Transport.send(message);

我正在尝试这样的事情

message.setContent(meeting, "MyMeeting");

但它抛出异常。任何想法我该怎么做?

1 个答案:

答案 0 :(得分:2)

以下是此

的解决方案
             try {
        MimeMessage message = new MimeMessage(session);
        message.setFrom(new InternetAddress("sender@emailID.com"));
        message.addRecipient(Message.RecipientType.TO, new InternetAddress("recepint@emailID.com"));
        message.setSubject("Hello iCal4j Meeting Invitation");

        // create the message part
        MimeBodyPart messageBodyPart = new MimeBodyPart();

        // fill message
        messageBodyPart.setText("Hi Sir, Please see the demo example to send meeting invitaiton from iCal4j API.");

        Multipart multipart = new MimeMultipart();
        multipart.addBodyPart(messageBodyPart);

        // Part two is attachment
        messageBodyPart = new MimeBodyPart();
        DataSource source = new FileDataSource(calFile);
        messageBodyPart.setDataHandler(new DataHandler(source));
        messageBodyPart.setFileName(calFile);
        multipart.addBodyPart(messageBodyPart);

        // Put parts in message
        message.setContent(multipart);

        Transport.send(message);
    //  System.out.println(meeting);

    } catch (MessagingException e) {
        throw new RuntimeException(e);
    }