简体   繁体   中英

Create Outlook Calendar Recurring meeting with attachment using java with the help of EWS api

I have created Outlook Calendar Recurring meeting with attachment using java with the help of EWS api. My meeting created successfully with the attachment in organiser account but receiver getting same meeting request without attachment in his calendar. I think I am missing something in my script please have a look script and suggest me where I can improve

public static void sendRecurringDailyAppointmentswithAttachment(String
appSubject, String appBody, int count, String recipient, String[] 
attachment) {
    ExchangeService sv = service();

    try {

        Appointment app = 
prepareRecurringDailyAppointmentwithAttachment(appSubject, appBody, count, 
sv, attachment );
            app.getRequiredAttendees().add(recipient);
            app.save();

    } catch (Exception e) {
        e.printStackTrace();
    }
}


private static Appointment 
prepareRecurringDailyAppointmentwithAttachment(String appSubject, String 
appBody, int count, ExchangeService sv, String[] attachment) throws   {
    Appointment app = new Appointment(sv);
    app.setSubject(appSubject);
    app.setBody(MessageBody.getMessageBodyFromText(appBody));

    app.setStart(getNextHourDate());
    app.setEnd(getDateWithHourDelta(2));
    app.getAttachments();

    if (attachment != null){
        for (String fileName : attachment){
              System.out.println("... adding attachment " + fileName);
              app.getAttachments().addFileAttachment(fileName);

        }
 }

    app.setRecurrence(new Recurrence.DailyPattern(app.getStart(), 1));

    app.getRecurrence().setStartDate(app.getStart());
    app.getRecurrence().setNumberOfOccurrences(count);
    return app;
}

I think you need to save the appointment with the attachment first:

if (attachment != null){
    for (String fileName : attachment){
          System.out.println("... adding attachment " + fileName);
          app.getAttachments().addFileAttachment(fileName);
    }
app.save();

Then add attendees and make an update:

app.getRequiredAttendees().add(recipient);
app.update(ConflictResolutionMode.AutoResolve, SendInvitationsOrCancellationsMode.SendOnlyToAll);
public static void sendRecurringDailyAppointmentswithAttachment(String
appSubject, String appBody, int count, String recipient, String[] 
attachment) {
ExchangeService sv = service();

try {

    Appointment app = 
prepareRecurringDailyAppointmentwithAttachment(appSubject, appBody, count, 
sv, attachment );
        app.getRequiredAttendees().add(recipient);
        app.update(ConflictResolutionMode.AutoResolve);

} catch (Exception e) {
    e.printStackTrace();
}
}


private static Appointment 
prepareRecurringDailyAppointmentwithAttachment(String appSubject, String 
appBody, int count, ExchangeService sv, String[] attachment) throws   {
Appointment app = new Appointment(sv);
app.setSubject(appSubject);
app.setBody(MessageBody.getMessageBodyFromText(appBody));

app.setStart(getNextHourDate());
app.setEnd(getDateWithHourDelta(2));
app.getAttachments();

if (attachment != null){
    for (String fileName : attachment){
          System.out.println("... adding attachment " + fileName);
          app.getAttachments().addFileAttachment(fileName);

    }
app.save();
}

app.setRecurrence(new Recurrence.DailyPattern(app.getStart(), 1));

app.getRecurrence().setStartDate(app.getStart());
app.getRecurrence().setNumberOfOccurrences(count);
return app;
}

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