2017-02-14 8 views
0

私はOffice 365メールボックスに接続してからxlsファイルを使って電子メールを受け取って共有フォルダに入れるc#スクリプトを持っていました。今問題はOFFICE 365メールボックスがOutlook 2010の構内メールボックスになり、スクリプトが機能しなくなりました。C# - Xlsファイルを取るためにOutlook 2010のメールボックスに接続

私の質問は、どのサービス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のは、主にウェブベースで、Office 2010のではありませんでした。 OWAは見通しではありません。OWAは必ずしも事前に設定する必要はありませんでした。 – BugFinder

答えて

関連する問題