EWS fileAttachment.ContentType 始终为空?

EWS fileAttachment.ContentType always null?

我目前正在开发这项 windows 服务,该服务从交换 Web 服务中提取数据。一切正常,但我无法获取邮件附件的 contentType / Mime 类型。

任何人都可以指出我在哪里找到问题的方向吗?

 protected override void OnStart(string[] args)
    {
        Svc = new ExchangeService(ExchangeVersion.Exchange2010_SP2);
        Svc.Credentials = new WebCredentials("kbatest@xxxx.xx", "kba123test");
        Svc.TraceEnabled = true;
        Svc.TraceFlags = TraceFlags.All;
        Svc.AutodiscoverUrl("kbatest@xxxx.xx", RedirectionUrlValidationCallback);

        streamsubscript = Svc.SubscribeToStreamingNotifications(new FolderId[] { WellKnownFolderName.Inbox }, EventType.NewMail);

        connection = new StreamingSubscriptionConnection(Svc, 30);
        connection.AddSubscription(streamsubscript);
        connection.OnNotificationEvent += OnNotificationEvent;
        connection.OnSubscriptionError += ConnectionOnOnSubscriptionError;
        connection.OnDisconnect += ConnectionOnOnDisconnect;
        connection.Open();
    }

private void OnNotificationEvent(object sender, NotificationEventArgs args)
    {
        foreach (var notification in args.Events)
        {
            if (notification.EventType != EventType.NewMail) continue;

            var itemEvent = (ItemEvent)notification;
            mail = GetMailByID(itemEvent.ItemId.UniqueId);

            List<int> ls = ExtractTicketNumber(mail.Subject);

            if (ls.Count > 0)
            {
                foreach (int i in ls)
                {
                    bool exist = CheckTicketExistance(i);

                    if (exist)
                    {
                        SaveMailToEvent(mail, i);
                    }
                }
            }
            else
            {
                SaveMailToTicket(mail);
            }
        }
    }   


 private void SaveMailToEvent(EmailMessage mail, int ticketId)
    {
        string[] mailAddr = mail.From.Address.Split(new char[] { '@' });
        string user = mailAddr[0].ToUpper();
        var eventId = 0;

        using (var conn = new SqlConnection(connectionStr))
        {
            conn.Open();
             eventId = conn.Query<int>("INSERT INTO THGITTicketEvents (EventStatus, CreatedBy, Comment, RefTicketRecID, FileAttached)" +
                        "Values(@EventStatus, @CreatedBy, @Comment, @RefTicketRecID, @FileAttached)" +
                        "SELECT CAST( @@IDENTITY AS int)",
                         new
                         {
                             EventStatus = 9,
                             CreatedBy = user,
                             Comment = mail.Body.Text,
                             RefTicketRecID = ticketId,
                             FileAttached = (mail.HasAttachments) ? 1 : 0
                         }).Single();
        }

        if (mail.HasAttachments)
        {
            using (var conn = new SqlConnection(connectionStr))
            {
                conn.Open();

                foreach (var i in mail.Attachments)
                {
                    FileAttachment fileAttachment = i as FileAttachment;
                    if (fileAttachment != null)
                    {
                        fileAttachment.Load();
                        string test = fileAttachment.ContentType;
                        conn.Query("INSERT INTO THGITAttachments (FileContent, CreatedBy, FileName, RefEventRecID, MimeType)" +
                                   "Values(@FileContent, @CreatedBy, @FileName, @RefEventRecID, @MimeType)",
                            new
                            {
                                FileContent = fileAttachment.Content,
                                CreatedBy = user,
                                FileName = fileAttachment.Name,
                                RefEventRecID = eventId,
                                MimeType = fileAttachment.ContentType,
                            });
                    }
                }
            }
        }

    }

检查 EWSEditor 以查看附件是否确实设置了 属性。