2017-02-14 2 views
0

У меня был сценарий C#, который подключается к почтовому ящику OFFICE 365, а затем берет любые письма с файлом xls и помещает их в общую папку. Проблема заключается в том, что почтовый ящик OFFICE 365 становится почтовым ящиком в почтовом ящике Outlook 2010, и скрипт перестает работать.C# - подключиться к почтовому ящику Outlook 2010 для получения файлов Xls

Мои вопросы - это то, что я использую для служебного URL и учетных данных службы. Является ли тот же синтаксис или мне нужен новый способ подключения в скрипте?

OLD сценарий

using System; 
using System.Data; 
using Microsoft.SqlServer.Dts.Runtime; 
using System.Windows.Forms; 
using System.Net; 
using System.Net.Security; 
using System.Security.Cryptography.X509Certificates; 
using Microsoft.Exchange.WebServices.Data; 

namespace ST_0710846949654fbd84606ec3011bd081.csproj 
{ 
    [System.AddIn.AddIn("ScriptMain", Version = "1.0", Publisher = "", Description = "")] 
    public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase 
    { 

     #region VSTA generated code 
     enum ScriptResults 
     { 
      Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success, 
      Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure 
     }; 
     #endregion 

    /* 
     The execution engine calls this method when the task executes. 
     To access the object model, use the Dts property. Connections, variables, events, 
     and logging features are available as members of the Dts property as shown in the following examples. 

     To reference a variable, call Dts.Variables["MyCaseSensitiveVariableName"].Value; 
     To post a log entry, call Dts.Log("This is my log text", 999, null); 
     To fire an event, call Dts.Events.FireInformation(99, "test", "hit the help message", "", 0, true); 

     To use the connections collection use something like the following: 
     ConnectionManager cm = Dts.Connections.Add("OLEDB"); 
     cm.ConnectionString = "Data Source=localhost;Initial Catalog=AdventureWorks;Provider=SQLNCLI10;Integrated Security=SSPI;Auto Translate=False;"; 

     Before returning from this method, set the value of Dts.TaskResult to indicate success or failure. 

     To open Help, press F1. 
    */ 


     public void Main() 
     { 
      ExchangeService service = new ExchangeService(); 
      service.TraceEnabled = true; 
      service.TraceFlags = TraceFlags.All; 



      service.Credentials = new WebCredentials("[email protected]", "PasswordXXXXXXXXX", "mail.xxxxxxxxxxxxxxx.co.uk"); 
      service.Url = new Uri("https://mail.xxxxxxxxxxx.co.uk/owa"); 

      // Variable population 
      string FileName1 = null; 
      string attSaveLocation = Dts.Variables["User::attSaveLocation"].Value.ToString(); 
      string destfold = Dts.Variables["User::destFolder"].Value.ToString(); 
      string emailFrom = Dts.Variables["User::emailFrom"].Value.ToString(); 
      string filetype = Dts.Variables["User::filetype"].Value.ToString(); 

      //find items in the email folder 
      FindItemsResults<Item> foundItems = 
      service.FindItems(WellKnownFolderName.Inbox, new ItemView(600)); //can limit how many results are pulled 

      foreach (Item item in foundItems) 
      { 
       string tmpitemid; 
       string processed = null; 
       tmpitemid = item.Id.ToString(); 
       if (item is EmailMessage) 
       { 
        // Bind to an existing message item, requesting its Id property (using the tmpitemid) plus its attachments collection. 
        EmailMessage foundEmail = EmailMessage.Bind(service, new ItemId(tmpitemid), new PropertySet(BasePropertySet.IdOnly, ItemSchema.Attachments)); 
        EmailMessage foundEmail2 = (EmailMessage)item; 
        FindFoldersResults findResults = service.FindFolders(WellKnownFolderName.Inbox, new FolderView(10)); 

        //get the from e-mail address for exchange addresses 
        string fromaddress = null; 
        NameResolutionCollection nd = service.ResolveName(foundEmail2.From.Address); 
        foreach (NameResolution nm in nd) 
        { 
         if (nm.Mailbox.RoutingType == "SMTP") 
         { 
          fromaddress = nm.Mailbox.Address.ToLower(); 
         } 
         else 
         { 
          fromaddress = foundEmail2.From.Address.ToString().ToLower(); 
         } 
        } 
        //for other addresses 
        if (fromaddress == null) 
        { 
         fromaddress = foundEmail2.From.Address.ToString().ToLower(); 
        } 
        //if the email address is like the parameter 
        if (fromaddress.Contains(emailFrom)) 
        { 
         //process attachments 
         foreach (Attachment attachment in foundEmail.Attachments) 
         { 
          if (attachment is FileAttachment) 
          { 
           FileAttachment fileAttachment = attachment as FileAttachment; 
           FileName1 = attSaveLocation + fileAttachment.Name; 
           if (fileAttachment.Name.Contains(filetype)) 
           { 
            fileAttachment.Load(FileName1); 
            processed = "Y"; 
           } 
          } 
         } 
         if (processed == "Y") 
         { 
          // Get all the folders in the message's root folder. 
          Folder rootfolder = Folder.Bind(service, WellKnownFolderName.Inbox); 
          rootfolder.Load(); 
          foreach (Folder folder in rootfolder.FindFolders(new FolderView(100))) 
          { 
           if (folder.DisplayName == destfold) 
           { 
            foundEmail2.Move(folder.Id); 
           } 
          } 
         } 
        } 
       } 
      } 
      Dts.TaskResult = (int)ScriptResults.Success; 
     } 
    } 
} 
+0

Office 365 в основном веб-основе, офис 2010 не было. OWA не обменивается мнениями. OWA не обязательно должен был быть настроен раньше. – BugFinder

ответ

Смежные вопросы