none
More detailed example RRS feed

  • Question

  • Hi,

    Further to this, is there any similar way (like Outlook Redemption), to achieve, within Visual studio?

    Many Thanks & Best Regards, Hua Min

    Tuesday, January 2, 2018 7:26 AM

All replies

  • Hi HuaMin  Chen,

    you want to refer latest emails in Inbox.

    generally latest emails are unread.

    so you can try to retrieve unread messages to get latest emails.

    below is an example.

     private void ThisAddIn_Startup(object sender, System.EventArgs e)
            {
                Outlook.MAPIFolder inbox =
                    this.Application.ActiveExplorer().Session.GetDefaultFolder
                    (Outlook.OlDefaultFolders.olFolderInbox);
    
                Outlook.Items unreadItems = inbox.
                    Items.Restrict("[Unread]=true");
    
                MessageBox.Show(
                    string.Format("Unread items in Inbox = {0}", unreadItems.Count));
            }

    Reference:

    How to: Programmatically Retrieve Unread Messages from the Inbox

    further , you can modify the code to change the condition to find latest emails.

    Regards

    Deepak


    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.

    Wednesday, January 3, 2018 8:34 AM
    Moderator
  • Hi,

    How to achieve the same like Outlook redemption, in Visual studio?


    Many Thanks & Best Regards, Hua Min

    Wednesday, January 3, 2018 12:54 PM
  • Hi,

    Any help?


    Many Thanks & Best Regards, Hua Min

    Thursday, January 4, 2018 7:42 AM
  • Hi HuaMin  Chen,

    did you try to refer the example I suggested you in my last post?

    if yes, does it meet with your requirement?

    the code is to fetch unread mails from folder.

    let me know if you have any issue with the code.

    you can post the code part that you had tried.

    I will try to check it and try to provide you suggestion for that.

    Thanks for your understanding.

    Regards

    Deepak 


    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.

    Friday, January 5, 2018 4:24 AM
    Moderator
  • Hi,
    Do you have the way to connect to Outlook server by Outlook redemption, in Visual studio?

    Many Thanks & Best Regards, Hua Min


    Friday, January 5, 2018 7:36 AM
  • Hi HuaMin  Chen,

    you had asked,"Do you have the way to connect to Outlook server by Outlook redemption, in Visual studio?"

    Outlook redemption is not a product of Microsoft.

    so we are not familiar with Outlook redemption.

    if you want the solution using Outlook redemption then you need to contact the developers of Outlook redemption.

    on this forum, we can help you using VSTO.

    if you are available to use VSTO then you can refer the code example and let me know if you have any problem to executing that code.

    I will try to provide you further suggestions to solve the issue.

    Regards

    Deepak 


    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.

    Friday, January 5, 2018 8:38 AM
    Moderator
  • Hi Deepak,
    Can you please show the way to connec to one existing hotmail account, with password, and to retrieve Email inside, using Visual studio?

    Many Thanks & Best Regards, Hua Min

    Monday, January 8, 2018 9:37 AM
  • Hi HuaMin  Chen,

    if the account is already logged in outlook application then you not need to login again.

    example:

    using System;
    using System.Diagnostics;
    using System.Linq;
    using System.Reflection;
    using System.Runtime.InteropServices;
    using Outlook = Microsoft.Office.Interop.Outlook;
    
    namespace OutlookAddIn1
    {
        class Sample
        {
            Outlook.Application GetApplicationObject()
            {
    
                Outlook.Application application = null;
    
                // Check whether there is an Outlook process running.
                if (Process.GetProcessesByName("OUTLOOK").Count() > 0)
                {
    
                    // If so, use the GetActiveObject method to obtain the process and cast it to an Application object.
                    application = Marshal.GetActiveObject("Outlook.Application") as Outlook.Application;
                }
                else
                {
    
                    // If not, create a new instance of Outlook and log on to the default profile.
                    application = new Outlook.Application();
                    Outlook.NameSpace nameSpace = application.GetNamespace("MAPI");
                    nameSpace.Logon("", "", Missing.Value, Missing.Value);
                    nameSpace = null;
                }
    
                // Return the Outlook Application object.
                return application;
            }
    
        }
    }
    

    Reference:

    How to: Get and Log On to an Instance of Outlook

    to retrieve the mails you can refer code below.

    private static void ReadMailItems()
    {
        Application outlookApplication = null;
        NameSpace outlookNamespace = null;
        MAPIFolder inboxFolder = null;
        Items mailItems = null;
     
        try
        {
            outlookApplication = new Application();
            outlookNamespace = outlookApplication.GetNamespace("MAPI");
            inboxFolder = outlookNamespace.GetDefaultFolder(OlDefaultFolders.olFolderInbox);
            mailItems = inboxFolder.Items;
     
            foreach (MailItem item in mailItems)
            {
                var stringBuilder = new StringBuilder();
                stringBuilder.AppendLine("From: " + item.SenderEmailAddress);
                stringBuilder.AppendLine("To: " + item.To);
                stringBuilder.AppendLine("CC: " + item.CC);
                stringBuilder.AppendLine("");
                stringBuilder.AppendLine("Subject: " + item.Subject);
                stringBuilder.AppendLine(item.Body);
     
                Console.WriteLine(stringBuilder);
                Marshal.ReleaseComObject(item);
            }
        }
        catch { }
        finally
        {
            ReleaseComObject(mailItems);
            ReleaseComObject(inboxFolder); 
            ReleaseComObject(outlookNamespace); 
            ReleaseComObject(outlookApplication);
        }
    }
     
    private static void ReleaseComObject(object obj)
    {
        if (obj != null)
        {
            Marshal.ReleaseComObject(obj);
            obj = null;
        }
    }
     

    this VSTO code will work on client machine. note that VSTO does not work properly on server side.

    Considerations for server-side Automation of Office

    Regards

    Deepak


    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, January 9, 2018 8:22 AM
    Moderator
  • Hi,
    For instance, I have Exchange server within server

    182.173.77.208:33333

    what to adjust (to the codes), to refer to Exchange server, to read the Emails, per given account and password?

    Many Thanks & Best Regards, Hua Min

    Wednesday, January 10, 2018 4:39 AM
  • Hi HuaMin  Chen,

    you had mentioned that,"For instance, I have Exchange server within server"

    as i mentioned in my previous reply, VSTO will not work properly on server side.

    it is developed to work on client side.

    as a result, you can face the issues in link below.

     Considerations for server-side Automation of Office

    so it is not recommended to use VSTO on Server Side.

    Regards

    Deepak


    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.

    Wednesday, January 10, 2018 9:05 AM
    Moderator
  • Hi,

    I mean the way to directly connect to server on client machine. What to adjust to directly refer to mentioned IP (of given server), within Client machine? 


    Many Thanks & Best Regards, Hua Min


    • Edited by Jackson_1990 Wednesday, January 10, 2018 3:41 PM
    Wednesday, January 10, 2018 3:32 PM
  • Hi,

    Any advice?


    Many Thanks & Best Regards, Hua Min

    Monday, January 15, 2018 1:16 PM
  • Hi HuaMin  Chen,

    I am looking for a suitable example for your requirement.

    i will provide you as i will get it as soon as possible.

    Thanks for your understanding.

    Regards

    Deepak


    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, January 16, 2018 5:11 AM
    Moderator
  • Hi,

    When do you think it will be available?


    Many Thanks & Best Regards, Hua Min

    Friday, January 19, 2018 7:35 AM
  • Hi HuaMin  Chen,

    I try to find an example to login with IP.

    Unfortunately, I did not get any example or any article, reference, documentation on it.

    It looks like we need to use Username and password for login as mentioned in the code that i posted in my previous reply.

    So, It looks like currently it is not possible to login directly using IP.

    Work around is already provided by Dmitry Streblechenko _MVP_ in your previous thread which you mentioned in the original post. 

    Thanks for your understanding.

    Regards

    Deepak 


    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.

    Friday, January 19, 2018 8:30 AM
    Moderator
  • Hi Deepak,

    Do you mean the example related to redemption? If yes, can we achieve the same by Visual studio?


    Many Thanks & Best Regards, Hua Min

    Friday, January 19, 2018 1:09 PM
  • Hi HuaMin  Chen,

    You had asked,"Do you mean the example related to redemption? If yes, can we achieve the same by Visual studio?"

    No, We are not familiar with redemption. Here I am talking about Outlook Interop in Visual Studio.

    I did not get any example, documentation, article, link to achieve the same using Outlook Interop in Visual Studio.

    Regards

    Deepak


    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, January 22, 2018 8:07 AM
    Moderator
  • Hi,
    >> I did not get any example, documentation, article, link to achieve the same using Outlook Interop in Visual Studio.

    There should be one way to achieve this, right?

    Many Thanks & Best Regards, Hua Min

    Monday, January 22, 2018 10:09 AM
  • Hi HuaMin  Chen,

    Currently, With the use of Outlook Interop I did not get any way to achieve this.

    If anything new get introduce in future that can able to achieve this then i will try to update you about that.

    If the issue is urgent then you can try to generate a ticket for a paid support.

    Microsoft Support Engineer will work closely with your issue and try to provide helpful solution for your issue.

    Thanks for your understanding.

    Regards

    Deepak 


    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, January 23, 2018 9:35 AM
    Moderator
  • Hi Deepak,
    >> Microsoft Support Engineer will work closely with your issue and try to provide helpful solution for your issue.

    Does it mean this (achievable) way can only be got by paid ticket?

    Many Thanks & Best Regards, Hua Min

    Thursday, February 1, 2018 5:20 AM
  • Hi HuaMin  Chen,

    You had mentioned that,"Does it mean this (achievable) way can only be got by paid ticket?"

    No, It means that one engineer will be assigned to your issue and he will try to work on that issue.

    Then he can try to provide a suggestion or solution or a work around if any available.

    Regards

    Deepak


    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.

    Thursday, February 1, 2018 6:28 AM
    Moderator