【问题标题】:How to import Microsoft Exchange data to SQL in SSIS如何在 SSIS 中将 Microsoft Exchange 数据导入 SQL
【发布时间】:2023-03-17 04:19:01
【问题描述】:

我的老板给了我一份工作,将一个旧软件改写成一个 SSIS 包。我需要 SSIS:

  • 访问我们 Microsoft Exchange 服务器上的特定邮箱
  • 查看所有未读邮件并根据其文件类型从中下载附件
  • 将这些文件的内容(可通过记事本读取的文本)导入 SQL 表中
  • 将电子邮件主题导入另一个 SQL 表

我不确定我上面描述的内容是否在标准 SSIS 包中可用(我对此表示怀疑)——也许我需要下载一些库。到目前为止,我找到了this。它会成功吗?如果没有,您知道使用 SSIS 实现我想要的任何其他方法吗?

【问题讨论】:

    标签: sql sql-server ssis exchange-server


    【解决方案1】:

    最好的方法是使用Microsoft Exchange Webservices (=EWS) 下载并使用work with all kind of attachments(这里是example)。

    但是,由于这是一个 API,您需要在 MS Exchange 和您的 SQL Server 之间基于EWS API 构建某种中间件。可能是这样的:

    //TODO: Replace these with your values
    NetworkCredential exchangeAccessAccount = new NetworkCredential(@"UserName", @"Password", @"Domain");
    Uri OutlookWebAccessUri = new Uri(@"[[Outlook Web Access Url]]/EWS/Exchange.asmx");
    DateTime CalanderStart = new DateTime();
    DateTime CalanderEnd = new DateTime();
    int MaxItemsToReturn = 99999;
    
    try
    {
        #region create service binding
    
        // Create the service binding.
        ExchangeService esb = new ExchangeService(ExchangeVersion.Exchange2007_SP1);
        esb.Credentials = exchangeAccessAccount;
        esb.Url = OutlookWebAccessUri;
        esb.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.PrincipalName, Variables.UserDomainID.ToString());
    
        #endregion
    
        #region create CalendarView
    
        CalendarView calendarView = new CalendarView(CalanderStart, CalanderEnd, MaxItemsToReturn);
        calendarView.PropertySet = PropertySet.IdOnly;
    
        #endregion
    
        #region retrieve responce
    
        // Do the EWS Call...
        FindItemsResults<Appointment> findItemResponse = esb.FindAppointments(WellKnownFolderName.Calendar, calendarView);
    
        if (findItemResponse == null)
        {
            return;
        }
    
        #endregion
    
        #region load atendee data
    
        //get additional properties for each item returned by view, do this as view cannot return a lot of useful stuff like attendees
        ServiceResponseCollection<ServiceResponse> addProperties = 
                    esb.LoadPropertiesForItems(from Item item in findItemResponse select item,
                    new PropertySet(
                            BasePropertySet.IdOnly,
                            AppointmentSchema.Resources,
                            AppointmentSchema.RequiredAttendees,
                            AppointmentSchema.OptionalAttendees,
                            AppointmentSchema.Subject,
                            AppointmentSchema.Start,
                            AppointmentSchema.End,
                            AppointmentSchema.IsCancelled
                            ));
    
        List<Appointment> additionalProperties = new List<Appointment>(addProperties.Count);
    
        if (addProperties != null)
        {
            foreach (ServiceResponse currentResponce in addProperties)
            {
               additionalProperties.Add(((Appointment)((GetItemResponse)currentResponce).Item));
            }
        }
    
        #endregion
    
        #region process appts
    
        Appointment currentAppointmentAddProps = null;
    
        foreach (Appointment currentAppointment in findItemResponse)
        {
            #region find additional properties for current Appointment
    
            currentAppointmentAddProps = additionalProperties.Find(delegate(Appointment arg)
                  { return arg.Id == currentAppointment.Id; });
    
            #endregion
    
            //add data to output here
           OutputRecordSetBuffer.ActualEndDate = currentAppointmentAddProps.End;
    
        }
    
        #endregion
    }
    catch (Exception e)
    {
    
    }
    

    (更多信息here)

    【讨论】:

      【解决方案2】:

      事实证明,默认 SSIS 库没有连接到 Exchange 服务器所需的组件。我找到了 2 个第三方库,可以让你这样做:

      它们都是付费的,但也有免费的测试版本。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-04-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-01-28
        • 1970-01-01
        相关资源
        最近更新 更多