You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过EWS及ews-javascript-api获取会议(含当日会议)参会者邮箱列表

使用ews-javascript-api获取指定会议的参会者邮箱列表

Hey there! Let's walk through exactly how to use the ews-javascript-api to fetch the attendee email list for a specific meeting, whether you're working with a known meeting ID or searching by name within a 1-day window. Here's a step-by-step breakdown tailored to your requirements:

前置准备

First things first:

  • Install the required package via npm: npm install ews-javascript-api
  • Make sure your Exchange server allows EWS access, and your account has permissions to read calendar items.

核心实现代码

Step 1: Initialize the EWS Service Connection

Start by setting up the connection to your Exchange server. Adjust the host based on your environment (Office 365 vs. on-prem Exchange):

const ews = require('ews-javascript-api');

// Configure your Exchange credentials and server details
const exchangeConfig = {
  username: 'your-exchange-email@domain.com',
  password: 'your-email-password',
  host: 'outlook.office365.com' // For on-prem, use something like 'exchange.yourcompany.com'
};

// Initialize the EWS service
const ewsService = new ews.ExchangeService(ews.ExchangeVersion.Exchange2016);
ewsService.Credentials = new ews.WebCredentials(exchangeConfig.username, exchangeConfig.password);
ewsService.Url = new ews.Uri(`https://${exchangeConfig.host}/EWS/Exchange.asmx`);

Step 2: Fetch Attendees by Meeting ID

If you have the exact meeting ID, this is the fastest way to get attendees:

async function getAttendeesByMeetingId(meetingId) {
  try {
    // Bind to the specific meeting using its ID
    const meeting = await ews.Appointment.Bind(ewsService, new ews.ItemId(meetingId));
    
    // Load the Attendees property (it's not fetched by default)
    await meeting.Load(new ews.PropertySet(ews.ItemSchema.Attendees));
    
    // Extract just the email addresses from the attendee objects
    const attendeeEmails = meeting.Attendees.map(attendee => attendee.Address);
    
    return attendeeEmails;
  } catch (error) {
    console.error('Failed to retrieve attendees:', error);
    throw error;
  }
}

// Example usage:
// getAttendeesByMeetingId('your-unique-meeting-id').then(emails => console.log('Attendee emails:', emails));

Step 3: Fetch Attendees by Meeting Name + 1-Day Time Range

If you only have the meeting name and need to target today's instance, use a filtered search:

async function getAttendeesByMeetingName(meetingName) {
  try {
    // Define today's time window: start at midnight, end at midnight tomorrow
    const todayStart = new Date();
    todayStart.setHours(0, 0, 0, 0);
    const todayEnd = new Date(todayStart);
    todayEnd.setDate(todayEnd.getDate() + 1);

    // Build search filters: match meeting name + fall within today's window
    const subjectFilter = new ews.SearchFilter.IsEqualTo(ews.ItemSchema.Subject, meetingName);
    const startDateFilter = new ews.SearchFilter.IsGreaterThanOrEqualTo(ews.AppointmentSchema.Start, todayStart);
    const endDateFilter = new ews.SearchFilter.IsLessThan(ews.AppointmentSchema.End, todayEnd);
    const combinedFilter = new ews.SearchFilter.SearchFilterCollection(ews.LogicalOperator.And, [subjectFilter, startDateFilter, endDateFilter]);

    // Set up the item view (we'll grab the first matching meeting; adjust if you expect multiple)
    const view = new ews.ItemView(1);
    view.PropertySet = new ews.PropertySet(ews.ItemSchema.Attendees);

    // Execute the search against the calendar folder
    const searchResults = await ewsService.FindItems(ews.WellKnownFolderName.Calendar, combinedFilter, view);
    
    if (searchResults.Items.length === 0) {
      console.log('No matching meeting found for today');
      return [];
    }

    // Extract attendee emails from the found meeting
    const meeting = searchResults.Items[0];
    const attendeeEmails = meeting.Attendees.map(attendee => attendee.Address);
    
    return attendeeEmails;
  } catch (error) {
    console.error('Failed to retrieve attendees:', error);
    throw error;
  }
}

// Example usage:
// getAttendeesByMeetingName('Team Weekly Sync').then(emails => console.log('Attendee emails:', emails));

Key Notes to Keep in Mind

  • Server URL Check: For on-premise Exchange, verify the EWS endpoint (it might be https://your-exchange-server/EWS/Exchange.asmx). Office 365 uses the URL provided in the example.
  • Duplicate Meetings: If multiple meetings share the same name on the same day, adjust the ItemView count (e.g., new ews.ItemView(5)) and add extra filters (like meeting organizer) to narrow down the correct one.
  • Permissions: Ensure your account has read access to the calendar where the meeting is stored. If you're accessing another user's calendar, you'll need to adjust the folder reference to their calendar.
  • Error Handling: The try/catch blocks will catch common issues like invalid credentials, missing meetings, or permission errors—feel free to expand them for more specific error messaging.

内容的提问来源于stack exchange,提问作者0xh8h

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 12:19:57