1

Microsoft Graph或Outlook REST API是否支持將現有電子郵件導入Office 365郵箱?將現有電子郵件導入Office 365同時保留原始日期

根據定義,導入意味着複製電子郵件的方式保留其原始信息,包括其創建/發送/接收日期。因此

任我已經錯用它們,或者它僅僅是他們不支持設置與日期:

我都試過這些端點無濟於事相關領域。

回答

1

不,這些API沒有任何導入功能。不過這是個好主意!您應該在我們的UserVoice論壇上輸入內容。

+0

啊,會的。同時,提供這種能力的最接近的API是什麼? EWS託管API會訣竅嗎? – lolski

+0

EWS可以做到這一點,特別是如果你有一個MIME流來導入:https://msdn.microsoft.com/en-us/library/office/dn672319(v=exchg.150).aspx –

0

什麼,我能理解,你有現有的電子郵件某處歸檔服務器上,並且你想將它們導入到Outlook在線或Outlook Office 365的

你能做什麼,你可以利用交易所和Web服務導入您導出的電子郵件。大多數電子郵件可以通過.eml或.msg格式導入。我可以爲您提供.eml文件的指導。

在您的歸檔服務器,你可以獲取郵件的.eml文件備份,也可以通過從Outlook桌面/ Mozilla Thunderbird中導出郵件用於測試目的生成一個。

現在你可以使用NuGet包Microsoft.Exchange.WebServices這實際上是託管API爲Microsoft Exchange Web服務

您可以利用下面的代碼

void main() 
    { 
     ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP2); 
     // Get the information of the account 
     service.Credentials = new WebCredentials("account email here", "account password here"); 
     service.AutodiscoverUrl("account email here", RedirectionUrlValidationCallback); 
     UploadMIMEEmail(service); 
    } 

    public static bool RedirectionUrlValidationCallback(string redirectionUrl) 
    { 
     // The default for the validation callback is to reject the URL. 
     bool result = false; 

     Uri redirectionUri = new Uri(redirectionUrl); 

     // Validate the contents of the redirection URL. In this simple validation 
     // callback, the redirection URL is considered valid if it is using HTTPS 
     // to encrypt the authentication credentials. 
     if (redirectionUri.Scheme == "https") 
     { 
      result = true; 
     } 
     return result; 
    } 


    private static void UploadMIMEEmail(ExchangeService service) 
    { 
     EmailMessage email = new EmailMessage(service); 

     string emlFileName = @"E:\asad.eml"; 

     using (FileStream fs = new FileStream(emlFileName, FileMode.Open, FileAccess.Read)) 
     { 
      byte[] bytes = new byte[fs.Length]; 
      int numBytesToRead = (int)fs.Length; 
      int numBytesRead = 0; 

      while (numBytesToRead > 0) 
      { 
       int n = fs.Read(bytes, numBytesRead, numBytesToRead); 

       if (n == 0) 
        break; 

       numBytesRead += n; 
       numBytesToRead -= n; 
      } 

      // Set the contents of the .eml file to the MimeContent property. 
      email.MimeContent = new MimeContent("UTF-8", bytes); 
     } 

     // Indicate that this email is not a draft. Otherwise, the email will appear as a 
     // draft to clients. 
     ExtendedPropertyDefinition PR_MESSAGE_FLAGS_msgflag_read = new ExtendedPropertyDefinition(3591, MapiPropertyType.Integer); 
     email.SetExtendedProperty(PR_MESSAGE_FLAGS_msgflag_read, 1); 

     // This results in a CreateItem call to EWS. The email will be saved in the Inbox folder. 
     email.Save(WellKnownFolderName.Inbox); 
    } 

什麼這種方法確實是上傳以導入的電子郵件的形式向交換服務器發送電子郵件,其中所有電子郵件數據都與導出的.eml中的完全一致

如果Exchange服務器是域之內本地運行/那麼你可以通過

service.Url = new Uri("https://computername.domain.contoso.com/EWS/Exchange.asmx"); 

另外如果你想使用默認憑證,然後登錄還可以指定交換URL可以指定

service.UseDefaultCredentials = true; 

欲瞭解更多信息,您可以關注

https://msdn.microsoft.com/en-us/library/office/dn672319(v=exchg.150).aspx#bk_importproperties

https://code.msdn.microsoft.com/how-to-import-vcard-files-ffa0ff50

相關問題