캘린더를 이용한 회의 요청 취소
Contents
[
Hide
]
Aspose.Email의 Appointment 클래스를 사용해 회의 취소 요청을 보낼 수 있습니다. 요청을 취소하려면 원래 회의 요청 정보가 필요합니다. 이 문서의 예제는 먼저 회의 요청을 보내고 정보를 데이터베이스에 저장한 뒤, 메시지 ID를 기반으로 요청을 취소합니다.
회의 요청 보내기
우리가 하기 전에 회의 요청 취소, 우리는 일부를 전송해야 합니다:
- 먼저 메시지를 전송하기 위해 SmtpClient 유형의 인스턴스를 생성합니다.
- 모든 참석자 정보를 MailAddressCollection 컬렉션에 저장합니다.
- MailMessage 클래스의 인스턴스를 생성하고 From, To, Subject와 같은 필수 속성을 설정합니다.
- Appointment 유형의 인스턴스를 생성하고 위치, 시작 시간, 종료 시간, 주최자 및 참석자 정보를 지정합니다.
- 모든 정보를 데이터베이스에 저장합니다. 데이터베이스 관련 작업은 SaveIntoDB 메서드에서 수행됩니다.
다음 코드 스니펫은 회의 요청을 보내는 방법을 보여줍니다.
class Attendees {
public String MessageId;
public String EmailAddress;
public String DisplayName;
}
class Message {
public String MessageId;
public String From;
public String Subject;
public String Body;
public String AppLocation;
public Date AppStartDate;
public Date AppEndDate;
public String AppSummary;
public String AppDescription;
}
public void send(Attendees[] attendeesArr, String from, String appLocation, Date appStartDate, Date appEndDate) {
try {
// Create an instance of SMTPClient
SmtpClient client = new SmtpClient("MailServer", "Username", "Password");
// Get the attendees
MailAddressCollection attendees = new MailAddressCollection();
for (Attendees a : attendeesArr) {
attendees.addItem(new MailAddress(a.EmailAddress, a.DisplayName));
}
// Create an instance of MailMessage for sending the invitation
MailMessage msg = new MailMessage();
// Set from address, attendees
msg.setFrom(new MailAddress(from));
msg.setTo(attendees);
// Create am instance of Appointment
Appointment app = new Appointment(appLocation, appStartDate, appEndDate, new MailAddress(from), attendees);
app.setSummary("Monthly Meeting");
app.setDescription("Please confirm your availability.");
msg.addAlternateView(app.requestApointment());
// Save the info to the database
if (saveIntoDB(msg, app) == true) {
// Save the message and Send the message with the meeting request
msg.save(msg.getMessageId() + ".eml", SaveOptions.getDefaultEml());
client.send(msg);
System.out.println("message sent");
}
} catch (Exception ex) {
System.err.println(ex);
}
}
private boolean saveIntoDB(MailMessage msg, Appointment app) {
// Save Message and Appointment information
Message messageRow = new Message();
messageRow.MessageId = msg.getMessageId();
messageRow.From = msg.getFrom().getAddress();
messageRow.Subject = msg.getSubject();
messageRow.Body = msg.getBody();
messageRow.AppLocation = app.getLocation();
messageRow.AppStartDate = app.getStartDate();
messageRow.AppEndDate = app.getEndDate();
messageRow.AppSummary = app.getSummary();
messageRow.AppDescription = app.getDescription();
addToDB(messageRow);
// Save attendee information
for (MailAddress address : app.getAttendees()) {
Attendees attendeesRow = new Attendees();
attendeesRow.MessageId = msg.getMessageId();
attendeesRow.EmailAddress = address.getAddress();
attendeesRow.DisplayName = address.getDisplayName();
addToDB(attendeesRow);
}
return true;
}
회의 요청 취소
회의 요청을 취소하려면 먼저 이메일 메시지의 메시지 ID를 가져와야 합니다. 이 예제에서는 해당 정보를 데이터베이스에 저장했으므로 쉽게 다시 가져올 수 있습니다.
- 취소 요청을 보낼 메시지를 선택합니다.
- Send Cancel Request 를 클릭해 요청을 보냅니다.
- 데이터베이스를 조회해 참석자, 메시지 및 캘린더 관련 정보를 가져옵니다.
- 데이터베이스에서 가져온 정보를 이용해 Calendar 클래스와 MailMessage 클래스의 인스턴스를 생성합니다.
- Appointment.cancelAppointment() 메서드를 사용해 취소 요청을 보냅니다.
- SMTP를 사용해 메일을 전송합니다.
다음 코드 스니펫은 회의 요청을 취소하는 방법을 보여줍니다.
public void cancel(String messageId) {
// Get the message and calendar information from the database get the attendee information
// Get the attendee information in reader
Attendees[] attendeesRows = getAttendeesFromDB(messageId);
// Create a MailAddressCollection from the attendees found in the database
MailAddressCollection attendees = new MailAddressCollection();
for (Attendees attendeesRow : attendeesRows) {
attendees.addItem(new MailAddress(attendeesRow.EmailAddress, attendeesRow.DisplayName));
}
// Get message and calendar information
Message messageRow = getMessageFromDB(messageId);
// Create the Calendar object from the database information
Appointment app = new Appointment(messageRow.AppLocation, messageRow.AppSummary, messageRow.AppDescription, messageRow.AppStartDate, messageRow.AppEndDate,
new MailAddress(messageRow.From), attendees);
// Create message and Set from and to addresses and Add the cancel meeting request
MailMessage msg = new MailMessage();
msg.setFrom(new MailAddress(messageRow.From));
msg.setTo(attendees);
msg.setSubject("Cencel meeting");
msg.addAlternateView(app.cancelAppointment());
SmtpClient smtp = new SmtpClient("smtp.gmail.com", 587, "user@gmail.com", "password");
smtp.send(msg);
System.out.println("cancellation request successfull");
}