Appointment 작업
ICS 형식으로 약속 로드 및 저장
다음은 Appointment Aspose.Email for Java의 클래스는 ICS 형식으로 약속을 로드할 수 있을 뿐만 아니라 새 약속을 생성하고 이를 디스크에 저장할 수도 있습니다. 이 문서에서는 먼저 약속을 생성하고 이를 ICS 형식으로 저장한 뒤 다시 로드합니다.
ICS 형식으로 약속 로드
ICS 형식으로 약속을 로드하려면 다음 단계가 필요합니다:
- 다음의 인스턴스를 생성합니다. Appointment 클래스.
- 다음을 호출합니다. load() 방법, ICS 파일의 경로를 제공합니다.
- 약속(ICS 파일)의 속성을 읽어 정보를 얻습니다.
다음 코드 조각은 ICS 형식으로 약속을 로드하는 방법을 보여줍니다.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
// Load the appointment from an ICS file
Appointment appointment = Appointment.load(dataDir + "appointment.ics");
// Read its properties
System.out.println("Summary: " + appointment.getSummary());
System.out.println("Location: " + appointment.getLocation());
System.out.println("Description: " + appointment.getDescription());
System.out.println("Start date: " + appointment.getStartDate());
System.out.println("End date: " + appointment.getEndDate());
System.out.println("Organizer: " + appointment.getOrganizer());
System.out.println("Attendees: " + appointment.getAttendees());
ICS 형식으로 약속을 생성하고 디스크에 저장
약속을 생성하고 이를 ICS 형식으로 저장하려면 다음 단계가 필요합니다.
- 다음의 인스턴스를 생성합니다. Appointment 클래스, 위치, 요약, 설명, 시작일, 종료일, 주최자 및 참석자를 생성자에 전달합니다.
- 출력에 필요하다면 생성 및 최종 수정 날짜를 설정하십시오.
- 다음을 호출합니다. save() 방법, 파일 이름 및 형식을 지정합니다.
이 약속은 Microsoft Outlook이나 ICS 파일을 로드할 수 있는 모든 프로그램에서 열 수 있습니다. 파일을 Microsoft Outlook에서 열면 자동으로 Outlook 캘린더에 약속이 추가됩니다.
다음 코드 조각은 약속을 생성하고 이를 ICS 형식으로 디스크에 저장하는 방법을 보여줍니다.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
// Set the start and end date of the appointment
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2026, java.util.Calendar.NOVEMBER, 1, 10, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2026, java.util.Calendar.NOVEMBER, 1, 11, 0, 0);
Date endDate = calendar.getTime();
MailAddressCollection attendees = new MailAddressCollection();
attendees.addMailAddress(new MailAddress("attendee@domain.com", "Attendee"));
// Location, summary, description, start, end, organizer and attendees
Appointment appointment = new Appointment(
"Room 112",
"Monthly Meeting",
"Please confirm your attendance.",
startDate,
endDate,
new MailAddress("organizer@domain.com", "Organizer"),
attendees);
appointment.setCreatedDate(new Date());
appointment.setLastModifiedDate(new Date());
// Save it in ICS format
appointment.save(dataDir + "appointment_out.ics", AppointmentSaveFormat.Ics);
약속을 MSG 형식으로 저장
Aspose.Email을 사용하면 약속을 .msg 파일에 직접 저장할 수 있습니다. 약속 저장 방식을 사용자 정의할 수 있는 다음 공개 클래스가 제공됩니다:
- AppointmentMsgSaveOptions msg 형식으로 약속을 저장하기 위한 추가 옵션을 제공하는 클래스입니다.
- AppointmentIcsSaveOptions 클래스에 추가 옵션과 함께 전달하여 약속을 ICS 형식으로 저장합니다. 이는 구식
IcsSaveOptions.
아래 코드 샘플은 파일에서 약속을 로드한 다음 .ics와 .msg 두 가지 다른 형식으로 저장하는 방법을 보여줍니다.
String dataDir = "data/";
Appointment appointment = Appointment.load(dataDir + "appointment.ics");
appointment.save(dataDir + "appointment_out.ics", new AppointmentIcsSaveOptions());
appointment.save(dataDir + "appointment_out.msg", new AppointmentMsgSaveOptions());
HTML 콘텐츠가 포함된 약속 생성
iCalendar(RFC 5545) 형식에서 X-ALT-DESC 헤더를 사용하는 것이 일반적인 관행입니다. 이는 캘린더 항목 또는 이벤트에 대한 대체 인간이 읽을 수 있는 설명을 제공하는 확장 속성입니다. 이 헤더는 종종 이벤트 설명의 일반 텍스트 또는 HTML 표현을 포함하는 데 사용되며, 오래된 캘린더 소프트웨어와의 호환성이나 설명의 단순화된 버전을 제공하는 데 유용합니다. 기본 설명이 수신자의 캘린더 애플리케이션에서 지원되지 않거나 제대로 표시되지 않을 때, X-ALT-DESC 헤더를 사용하여 이벤트에 대한 대체 설명을 제공합니다. 이는 발신자가 이벤트 설명의 다양한 표현을 포함하여 다양한 캘린더 소프트웨어와 플랫폼 간의 호환성과 접근성을 향상시킬 수 있게 합니다. HTML 콘텐츠가 포함된 약속을 만들려면, 마크업을 setHtmlDescription 방법. 아래 코드 샘플은 날짜, 시간, 위치, 주최자, 참석자 및 형식화된 설명이 포함된 약속을 생성합니다:
Date startDate = new Date();
// One hour later
Date endDate = new Date(startDate.getTime() + 60 * 60 * 1000);
MailAddressCollection attendees = new MailAddressCollection();
attendees.addMailAddress(new MailAddress("AinaMartensson@to.com", "Aina Martensson"));
Appointment appointment = new Appointment("Bygget 83",
startDate, // start date
endDate, // end date
new MailAddress("TintinStrom@from.com", "Tintin Strom"), // organizer
attendees); // attendees
appointment.setHtmlDescription("<html>\n"
+ " <style type=\"text/css\">\n"
+ " .text {\n"
+ " font-family:'Comic Sans MS';\n"
+ " font-size:16px;\n"
+ " }\n"
+ " </style>\n"
+ " <body>\n"
+ " <p class=\"text\">Hi, I'm happy to invite you to our party.</p>\n"
+ " </body>\n"
+ " </html>");
초안 약속 요청 생성
약속을 초안 모드로 저장하려면, 메서드 유형을 Appointment 클래스는 Publish 로 설정해야 하며 setMethodType. 접근자 이름에 주목하십시오: Aspose.Email for Java에서는 setMethodType, not setMethod. 다음 코드 샘플은 사용 방법을 보여줍니다.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
String sender = "sender@domain.com";
String recipient = "recipient@domain.com";
MailMessage message = new MailMessage(sender, recipient, "", "");
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2026, java.util.Calendar.NOVEMBER, 1, 0, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2026, java.util.Calendar.DECEMBER, 1, 0, 0, 0);
Date endDate = calendar.getTime();
MailAddressCollection attendees = new MailAddressCollection();
attendees.addMailAddress(new MailAddress("attendee@domain.com", "Attendee"));
Appointment app = new Appointment("", startDate, endDate,
new MailAddress("organizer@domain.com", "Organizer"), attendees);
// Publish marks the appointment as a draft rather than a request
app.setMethodType(AppointmentMethodType.Publish);
message.addAlternateView(app.requestApointment());
MapiMessage msg = MapiMessage.fromMailMessage(message);
// Save the appointment as a draft
msg.save(dataDir + "appointment-draft.msg");
텍스트에서 초안 약속 만들기
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
String ical = "BEGIN:VCALENDAR\r\n"
+ "METHOD:PUBLISH\r\n"
+ "PRODID:-//Aspose Ltd//iCalender Builder (v3.0)//EN\r\n"
+ "VERSION:2.0\r\n"
+ "BEGIN:VEVENT\r\n"
+ "ATTENDEE;CN=attendee@domain.com:mailto:attendee@domain.com\r\n"
+ "DTSTART:20130220T171439\r\n"
+ "DTEND:20130220T174439\r\n"
+ "DTSTAMP:20130220T161439Z\r\n"
+ "END:VEVENT\r\n"
+ "END:VCALENDAR";
MailMessage message = new MailMessage("sender@domain.com", "recipient@domain.com", "", "");
AlternateView av = AlternateView.createAlternateViewFromString(ical, new ContentType("text/calendar"));
message.getAlternateViews().addItem(av);
MapiMessage msg = MapiMessage.fromMailMessage(message);
// Save the appointment as a draft
msg.save(dataDir + "DraftAppointment.msg");
캘린더 항목에서 첨부 파일 추가 및 제거
Aspose.Email는 캘린더 항목과 연결된 첨부 파일을 추가하고 검색하는 데 사용할 수 있는 첨부 파일 컬렉션을 제공합니다. 이 문서에서는 다음 방법을 보여줍니다:
- 첨부 파일을 생성하고 추가합니다 Appointment 클래스 객체.
- 약속에서 첨부 파일 정보를 검색합니다.
- 약속에서 첨부 파일을 추출합니다.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
// The path to the resource directory.
String dataDir = "data/";
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2026, java.util.Calendar.NOVEMBER, 1, 0, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2026, java.util.Calendar.DECEMBER, 1, 0, 0, 0);
Date endDate = calendar.getTime();
MailAddressCollection attendees = new MailAddressCollection();
attendees.addMailAddress(new MailAddress("attendee@domain.com", "Attendee"));
WeeklyRecurrencePattern recurrence = new WeeklyRecurrencePattern(3);
Appointment app = new Appointment("Appointment Location", "Appointment Summary",
"Appointment Description", startDate, endDate,
new MailAddress("organizer@domain.com", "Organizer"), attendees, recurrence);
// Attach a file from disk to this appointment
File file = new File(dataDir + "sample.xlsx");
try (FileInputStream fis = new FileInputStream(file)) {
app.getAttachments().addItem(new Attachment(fis, file.getName()));
}
String savedFile = "appWithAttachments.ics";
app.save(dataDir + savedFile, AppointmentSaveFormat.Ics);
// Load it back and extract the attachments
Appointment loaded = Appointment.load(dataDir + savedFile);
System.out.println("Total Attachments: " + loaded.getAttachments().size());
for (int i = 0; i < loaded.getAttachments().size(); i++) {
Attachment att = loaded.getAttachments().get_Item(i);
System.out.println(att.getName());
// Save the attachment to disk
att.save(dataDir + att.getName());
}
약속 서식 지정
아래 프로그래밍 샘플은 다음을 사용하는 방법을 보여줍니다 AppointmentFormattingOptions 텍스트와 HTML을 서식 지정하는 클래스.
프로그래밍 샘플 - 텍스트 서식
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
Appointment appointment = Appointment.load(dataDir + "test.ics");
AppointmentFormattingOptions formattingOptions = new AppointmentFormattingOptions();
formattingOptions.setLocationFormat("Where: {0}");
formattingOptions.setTitleFormat("Subject: {0}");
formattingOptions.setDescriptionFormat("\r\n*~*~*~*~*~*~*~*~*~*\r\n{0}");
System.out.println(appointment.getAppointmentText(formattingOptions));
프로그래밍 샘플 - HTML 서식
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
Appointment appointment = Appointment.load(dataDir + "test.ics");
AppointmentFormattingOptions formattingOptions = AppointmentFormattingOptions.createAsHtml();
formattingOptions.setLocationFormat("<FONT SIZE=2 FACE=\"Arial\"><b>Where: {0}</b></FONT><BR>");
formattingOptions.setTitleFormat("<FONT SIZE=2 FACE=\"Arial\"><b>Subject: {0}</b></FONT><BR>");
formattingOptions.setDescriptionFormat("<P><FONT SIZE=2 FACE=\"Arial\">-----------<br><i>{0}</i></FONT></P>");
System.out.println(appointment.getAppointmentText(formattingOptions));
ICS를 MSG로 변환
API를 사용하면 약속을 메시지 객체로 쉽게 변환할 수 있습니다. 다음 코드 예제는 약속 요청을 MailMessage 또는 MapiMessage로 변환하는 방법을 보여줍니다:
String dataDir = "data/";
Appointment appointment = Appointment.load(dataDir + "appRequest.ics");
MailMessage eml = appointment.toMailMessage();
MapiMessage msg = appointment.toMapiMessage();
msg.save(dataDir + "appRequest.msg");
약속 버전 확인
약속의 버전을 결정하려면 getVersion() 메서드 Appointment 클래스. 파일이 어떤 버전을 기반으로 하는지 판단하는 데 도움이 되며, 다른 시스템 및 앱과의 통합을 보장합니다.
다음 코드 예제는 프로젝트에서 이 메서드를 사용하는 방법을 보여줍니다:
Appointment app = Appointment.load("data/meeting.ics");
// The version is a string that holds the ICS/VCS version, e.g. "2.0" for iCalendar
if ("2.0".equals(app.getVersion())) {
// do something
}
ICS 파일에서 다중 이벤트 읽기
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
List<Appointment> appointments = new ArrayList<Appointment>();
CalendarReader reader = new CalendarReader(dataDir + "US-Holidays.ics");
while (reader.nextEvent()) {
appointments.add(reader.getCurrent());
}
System.out.println("Number of events read: " + appointments.size());
// Reading events from a specific index
appointments = new ArrayList<Appointment>();
AppointmentLoadOptions options = new AppointmentLoadOptions();
options.setEventIndex(4);
// Start reading from the fifth event in the file
reader = new CalendarReader(dataDir + "US-Holidays.ics", options);
while (reader.nextEvent()) {
appointments.add(reader.getCurrent());
}
System.out.println("Number of events read from index 4: " + appointments.size());
ICS 파일에 여러 이벤트 쓰기
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
AppointmentIcsSaveOptions saveOptions = new AppointmentIcsSaveOptions();
saveOptions.setAction(AppointmentAction.Create);
CalendarWriter writer = new CalendarWriter(dataDir + "WriteMultipleEventsToICS_out.ics", saveOptions);
// Set the start and end date of the meeting
java.util.Calendar calendar = java.util.Calendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.set(2026, java.util.Calendar.JUNE, 19, 19, 0, 0);
Date startDate = calendar.getTime();
calendar.set(2026, java.util.Calendar.JUNE, 19, 20, 0, 0);
Date endDate = calendar.getTime();
MailAddressCollection attendees = new MailAddressCollection();
attendees.addItem(new MailAddress("recipient@domain.com"));
try {
for (int i = 0; i < 10; i++) {
Appointment app = new Appointment(
"Room 112", // location
startDate, // start time
endDate, // end time
new MailAddress("organizer@domain.com"), // organizer
attendees); // attendees
app.setDescription("Test body " + i);
app.setSummary("Test summary: " + i);
writer.write(app);
}
} finally {
writer.dispose();
}
약속 참석자의 참여자 상태 설정
Aspose.Email for Java를 사용하면 회신 메시지를 구성하는 동안 약속 참석자의 상태를 설정할 수 있습니다. 이것은 ICS 파일에 PARTSTAT 속성을 추가합니다.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String location = "Room 5";
java.util.Calendar c = java.util.Calendar.getInstance();
c.set(2026, java.util.Calendar.DECEMBER, 10, 10, 12, 11);
Date startDate = c.getTime();
c.set(2026, java.util.Calendar.DECEMBER, 10, 13, 11, 12);
Date endDate = c.getTime();
MailAddress organizer = new MailAddress("organizer@domain.com", "Organizer");
MailAddress attendee1 = new MailAddress("first@domain.com", "First attendee");
MailAddress attendee2 = new MailAddress("second@domain.com", "Second attendee");
attendee1.setParticipationStatus(ParticipationStatus.Accepted);
attendee2.setParticipationStatus(ParticipationStatus.Declined);
MailAddressCollection attendees = new MailAddressCollection();
attendees.addMailAddress(attendee1);
attendees.addMailAddress(attendee2);
Appointment target = new Appointment(location, startDate, endDate, organizer, attendees);
iCalendar용 제품 식별자 사용자 지정
Aspose.Email for Java를 사용하면 iCalendar 개체를 만든 제품 식별자를 가져오거나 설정할 수 있습니다. 약속 자체에 설정하거나 AppointmentIcsSaveOptions 저장할 때.
// For complete examples and data files, please go to https://github.com/aspose-email/Aspose.Email-for-Java
String dataDir = "data/";
Appointment appointment = Appointment.load(dataDir + "appointment.ics");
// Read the product identifier that created the iCalendar object
System.out.println("Product ID: " + appointment.getProductId());
// The identifier written to the output file can be set on the appointment ...
appointment.setProductId("-//My Company//My Product//EN");
// ... or on the save options
AppointmentIcsSaveOptions saveOptions = new AppointmentIcsSaveOptions();
saveOptions.setProductId("-//My Company//My Product//EN");
appointment.save(dataDir + "appointment_out.ics", saveOptions);
약속을 로드할 때 주소 유효성 검사를 우회하는 방법
Aspose.Email for Java는 이메일 유효성 검사 오류를 우회하려면 IgnoreSmtpAddressCheck 옵션 AppointmentLoadOptions 객체를 로드 호출에 전달합니다.
AppointmentLoadOptions lo = new AppointmentLoadOptions();
lo.setIgnoreSmtpAddressCheck(true);
Appointment appointment = Appointment.load("data/app.ics", lo);