C#控制台应用程序-解析Office 365收件箱

C#控制台应用程序-解析Office 365收件箱,c#,parsing,office365,C#,Parsing,Office365,通过我找到的一个名为EAGetMail的软件包,我成功了。不幸的是,我很快意识到他们有一个代币系统,这不是一个免费的方法 还有一些其他选择可用,比如使用outlookmail restapi,以及MimeKit,但我不知道如何实现最终结果,因为在这两个引用中都没有“从开始到结束”的代码来演示如何解析帐户的收件箱 我已经在Mimekit的帮助下开始写这篇文章,但我不确定这是否是正确的方法 我必须想象它看起来像: using (var client = new SmtpClient ()) {

通过我找到的一个名为
EAGetMail
的软件包,我成功了。不幸的是,我很快意识到他们有一个代币系统,这不是一个免费的方法

还有一些其他选择可用,比如使用
outlookmail restapi
,以及
MimeKit
,但我不知道如何实现最终结果,因为在这两个引用中都没有“从开始到结束”的代码来演示如何解析帐户的收件箱

我已经在
Mimekit
的帮助下开始写这篇文章,但我不确定这是否是正确的方法

我必须想象它看起来像:

using (var client = new SmtpClient ())
{
    client.Connect("outlook.office365.com", 587);
    client.Authenticate("myemail@office365account.com", "mypassword");

    var message = MimeMessage.Load(stream);
}
我不知道如何设置上面提到的
,也不知道是否可以使用
Mimekit
office365
来实现这一点


我愿意通过
EAGetMail
而不是的任何其他方法来寻找解决方案。如果有人有一个轻量级的解决方案,从实际建立连接到从收件箱中提取邮件,那将是非常好的选择

我使用了
EWS
(Exchange Web服务)获得它。这是我的密码:

private 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;
}
static void Main(string[] args)
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

    service.Credentials = new WebCredentials("email@myemail.com", "myPassword");
    service.AutodiscoverUrl("email@myemail.com", RedirectionUrlValidationCallback);

            //creates an object that will represent the desired mailbox
    Mailbox mb = new Mailbox(@"email@myemail.com");

    //creates a folder object that will point to inbox folder
    FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);

    //this will bind the mailbox you're looking for using your service instance
    Folder inbox = Folder.Bind(service, fid);

    //load items from mailbox inbox folder
    if (inbox != null)
    {
        FindItemsResults<Item> items = inbox.FindItems(new ItemView(100));

        foreach (var item in items)
        {
            item.Load();
            Console.WriteLine("Subject: " + item.Subject);
        }
    }
}   
private static bool RedirectionUrlValidationCallback(字符串redirectionUrl)
{
//验证回调的默认值是拒绝URL。
布尔结果=假;
Uri redirectionUri=新Uri(redirectionUrl);
//验证重定向URL的内容
//如果使用HTTPS,则重定向URL被视为有效
//加密身份验证凭据。
if(redirectionUri.Scheme==“https”)
{
结果=真;
}
返回结果;
}
静态void Main(字符串[]参数)
{
ExchangeService服务=新的ExchangeService(ExchangeVersion.Exchange2013\u SP1);
service.Credentials=新的WebCredentials(“email@myemail.com“,“我的密码”);
服务。自动发现URL(“email@myemail.com,重定向UrlValidationCallback);
//创建表示所需邮箱的对象
邮箱mb=新邮箱(@“email@myemail.com");
//创建指向收件箱文件夹的文件夹对象
FolderId fid=新的FolderId(WellKnownFolderName.Inbox,mb);
//这将绑定您正在使用服务实例查找的邮箱
文件夹收件箱=Folder.Bind(服务,fid);
//从邮箱文件夹加载项目
如果(收件箱!=null)
{
FindItemsResults items=inbox.FindItems(新项目视图(100));
foreach(项目中的var项目)
{
item.Load();
Console.WriteLine(“主题:+item.Subject”);
}
}
}   

我是通过
EWS
(Exchange Web服务)获得它的。这是我的密码:

private 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;
}
static void Main(string[] args)
{
    ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2013_SP1);

    service.Credentials = new WebCredentials("email@myemail.com", "myPassword");
    service.AutodiscoverUrl("email@myemail.com", RedirectionUrlValidationCallback);

            //creates an object that will represent the desired mailbox
    Mailbox mb = new Mailbox(@"email@myemail.com");

    //creates a folder object that will point to inbox folder
    FolderId fid = new FolderId(WellKnownFolderName.Inbox, mb);

    //this will bind the mailbox you're looking for using your service instance
    Folder inbox = Folder.Bind(service, fid);

    //load items from mailbox inbox folder
    if (inbox != null)
    {
        FindItemsResults<Item> items = inbox.FindItems(new ItemView(100));

        foreach (var item in items)
        {
            item.Load();
            Console.WriteLine("Subject: " + item.Subject);
        }
    }
}   
private static bool RedirectionUrlValidationCallback(字符串redirectionUrl)
{
//验证回调的默认值是拒绝URL。
布尔结果=假;
Uri redirectionUri=新Uri(redirectionUrl);
//验证重定向URL的内容
//如果使用HTTPS,则重定向URL被视为有效
//加密身份验证凭据。
if(redirectionUri.Scheme==“https”)
{
结果=真;
}
返回结果;
}
静态void Main(字符串[]参数)
{
ExchangeService服务=新的ExchangeService(ExchangeVersion.Exchange2013\u SP1);
service.Credentials=新的WebCredentials(“email@myemail.com“,“我的密码”);
服务。自动发现URL(“email@myemail.com,重定向UrlValidationCallback);
//创建表示所需邮箱的对象
邮箱mb=新邮箱(@“email@myemail.com");
//创建指向收件箱文件夹的文件夹对象
FolderId fid=新的FolderId(WellKnownFolderName.Inbox,mb);
//这将绑定您正在使用服务实例查找的邮箱
文件夹收件箱=Folder.Bind(服务,fid);
//从邮箱文件夹加载项目
如果(收件箱!=null)
{
FindItemsResults items=inbox.FindItems(新项目视图(100));
foreach(项目中的var项目)
{
item.Load();
Console.WriteLine(“主题:+item.Subject”);
}
}
}   

未尝试使用Office 365。。。但是你试过了吗?EWS将使用Office 365电子邮件帐户@Bearcat9425,我会这样尝试,但如果你手头有解决方案,我很想看看你的解决方案。这里有很多关于如何阅读EWS的帖子,还有关于如何使用API的MSDN,@Bearcat9425让它工作起来了!谢谢你的建议!未尝试使用Office365。。。但是你试过了吗?EWS将使用Office 365电子邮件帐户@Bearcat9425,我会这样尝试,但如果你手头有解决方案,我很想看看你的解决方案。这里有很多关于如何阅读EWS的帖子,还有关于如何使用API的MSDN,@Bearcat9425让它工作起来了!谢谢你的建议!