none
Reading Message and Downloading file from office 365 RRS feed

  • Question

  • I have a program that automatically reads messages from a pop or smtp server, gets the attachment for processing and then deletes the message. This works fine.

    The client has just moved their email to office 365. How do I do what I just described in my c# code for a email account using a Office 365 email?


    Saturday, October 26, 2019 5:34 PM

All replies

  • Did you search for this?  The POP and IMAP servers are at outlook.office365.com.  The SMTP server is at smtp.office365.com.

    Tim Roberts | Driver MVP Emeritus | Providenza & Boekelheide, Inc.

    Sunday, October 27, 2019 2:41 AM
  • Hi David32, 

    Thank you for posting here.

    According to your description, I make a test which read emails from exchange online (Office 365).

    Here’s my code:

            static void Main(string[] args)
            {
                ExchangeService service = new ExchangeService {
                    Credentials = new WebCredentials("email ", "password")
                };
                service.AutodiscoverUrl("email", RedirectionUrlValidationCallback);
                
                Console.WriteLine("Reading mail");
                // Read 1 mails.
                foreach (EmailMessage email in service.FindItems(WellKnownFolderName.Inbox, new ItemView(1)))
                {
                    email.Load(new PropertySet(BasePropertySet.FirstClassProperties, ItemSchema.TextBody));
                    Console.WriteLine(email.TextBody);
                }
                Console.WriteLine("Exiting");
                Console.ReadLine();
            }
            private static bool RedirectionUrlValidationCallback(string redirectionUrl)
            {
                bool result = false;
                Uri redirectionUri = new Uri(redirectionUrl);
                if (redirectionUri.Scheme == "https")
                {
                    result = true;
                }
                return result;
            }
    

    Result:

    Besides, you can refer to the following references to get and download attachments by using EWS in Exchange.

    1. Get attachments by using EWS in Exchange
    2. Download attachment from Exchange using Exchange Web Services

    Best Regards,

    Xingyu Zhao



    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, October 28, 2019 7:43 AM
    Moderator
  • Thanks for help.
    Monday, October 28, 2019 7:22 PM
  • Hi David32,

    Is your problem solved? If so, please click "Mark as answer" to the appropriate answer, so that it will help other members to find the solution quickly if they face a similar issue.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, October 29, 2019 9:29 AM
    Moderator