2

Microsoft Graph 或 Outlook REST API 是否支持将现有电子邮件导入 Office 365 邮箱?

根据定义,导入意味着以保留其原始信息的方式复制电子邮件,包括其创建/发送/接收日期。

我尝试了这些端点无济于事:

因此,要么我错误地使用了它们,要么只是它们不支持设置与日期相关的字段。

4

2 回答 2

2

不,API 没有任何导入功能。不过这是个好主意!您应该在我们的UserVoice论坛上注册。

于 2016-04-15T12:18:32.193 回答
0

我可以理解的是,您在存档服务器上的某处有现有的电子邮件,并且您希望将它们导入您的 Outlook Online 或 Outlook Office 365。

您可以使用 Exchange WebServices 并导入导出的电子邮件。大多数电子邮件可以通过 .eml 或 .msg 格式导入。我可以为您提供 .eml 文件的指导。

在您的存档服务器上,您可以获得电子邮件的 .eml 文件备份,或者您可以通过从 Outlook 桌面/Mozilla Thunderbird 导出电子邮件来生成一个备份以用于测试目的。

现在您可以使用 Nuget 包 Microsoft.Exchange.WebServices,它实际上是 Microsoft Exchange WebServices 的托管 API

您可以使用以下代码

    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 中完全相同。

如果您交换服务器在本地/域内运行,那么您还可以通过以下方式指定交换 URL

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

此外,如果您想使用默认凭据登录,那么您可以指定

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

于 2017-04-07T15:33:03.580 回答