Absagen von Besprechungsanfragen mit dem Kalender
Sie können mit Aspose.Email und dem Appointment‑Klassenobjekt eine Besprechungsabsage senden. Dazu benötigen Sie die ursprünglichen Besprechungsanfrage‑Informationen, um die Anfrage zu stornieren. Das Beispiel in diesem Artikel sendet zunächst eine Besprechungsanfrage, speichert die Informationen in einer Datenbank und storniert die Anfrage anschließend anhand der Nachrichten‑ID.
Versenden von Besprechungsanfragen
Bevor wir können Besprechungsanfragen absagen, wir müssen einige versenden:
- Erstellen Sie zuerst eine Instanz vom Typ SmtpClient zum Senden der Nachricht.
- Speichern Sie alle Teilnehmerinformationen in der MailAddressCollection‑Kollektion.
- Erstellen Sie eine Instanz der MailMessage‑Klasse und die notwendigen Eigenschaften wie From, To und Subject.
- Erstellen Sie eine Instanz vom Typ Appointment und geben Sie Standort, Startzeit, Endzeit, Organisatoren‑ und Teilnehmerinformationen an.
- Speichern Sie alle Informationen in einer Datenbank. Datenbank‑bezogene Arbeiten werden in der Methode SaveIntoDB durchgeführt.
Das folgende Code‑Snippet zeigt, wie man Besprechungsanfragen sendet.
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;
}
Absage von Besprechungsanfragen
Um eine Besprechungsanfrage abzusagen, holen Sie zuerst die Nachrichten‑ID der E‑Mail‑Nachricht. Da wir diese Information in einer Datenbank für dieses Beispiel gespeichert haben, können wir sie leicht wieder abrufen.
- Auswahl der Nachricht, für die die Absage gesendet werden soll.
- Klicken Sie auf Send Cancel Request, um die Anfrage zu senden.
- Fragt die Datenbank ab, um Informationen zu Teilnehmern, Nachrichten und Kalender zu erhalten.
- Erstellen Sie Instanzen der Calendar‑Klasse und der MailMessage‑Klasse mithilfe der aus der Datenbank abgerufenen Informationen.
- Verwenden Sie die Methode Appointment.cancelAppointment(), um die Absage zu senden.
- Senden Sie die Mail über das SMTP.
Das folgende Code‑Snippet zeigt, wie man die Besprechungsanfrage absagt.
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");
}