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

相关问题