none
Strange issue when launching Outlook Client from C# code RRS feed

  • Question

  • I have one C# application and need to launch Outlook client to send email for user. I am attaching my c# code below and it is working fine basically. When Outlook client was launched and email data were populated into Outlook client, if no attachment, it is working fine. If has attachment, Outlook client is not working. In detail, Outlook client was launched, but look like Outlook client was frozen, all buttons/links were frozen and not clickable, only top close button can be clicked. I am attaching image. You can see some controls on top of Outlook client page: "To...", "Cc...", "Subject" controls were on top of the page and they were duplicate. Send button is not clickable and this email can't be sent. I don't know what is wrong with me and any help/clue/suggestion will be appreciated it very much. Gary

    using Outlook = Microsoft.Office.Interop.Outlook;
    ................
    
     public static string launchOutlookClient(int Id, string ToEmailAddress,string Subject, string TextBody, string AttachmentFullPath)
            {
                try
                {        
     		Outlook.Application app = new Outlook.Application();
                    Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;
    
                    mail.Subject = Subject;
    
    		Outlook.Recipient r = mail.Recipients.Add(ToEmailAddress);
               	r.Type = (int)Outlook.OlMailRecipientType.olTo;
    
                    mail.Recipients.ResolveAll();
                    mail.Attachments.Add(AttachmentFullPath, 1, 1, "Attachment");
                                      
                    mail.PropertyAccessor.SetProperty(Prop, Id.ToString());       
                    mail.Body = TextBody;             
                    ((Outlook._MailItem)mail).Display();
                        return mail.ConversationIndex;
    
                }
                catch (Exception ex) { string s = ex.Message; return "Error: " + s; }
            }


    Gary Shi




    Wednesday, July 19, 2017 2:01 PM

Answers

  • Hi,

    try move ((Outlook._MailItem)mail).Display() between:

    Outlook.Application app = new Outlook.Application(); Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;

    ((Outlook._MailItem)mail).Display();

    mail.Subject = Subject; 

    [...]

    ms

    • Marked as answer by Gary_MSDN Monday, November 27, 2017 9:01 PM
    Sunday, October 29, 2017 9:12 AM
  • Hi Gary_MSDN,

    if you are available with Office insider then you can try to submit a feedback from there. because Office insider has an option to submit any bug related report to Microsoft.

    if you are not available with that then you can try to submit the issue to Outlook user voice.

    Outlook Feedback

    to work around this issue you can try to make a test with Windows 10 OS because I had check many times and with Windows 10 OS it is working correctly.

    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.

    • Marked as answer by Gary_MSDN Friday, July 28, 2017 1:25 PM
    Monday, July 24, 2017 5:20 AM
    Moderator

All replies

  • Hi Gary,

    According to your question is more related to OutLook , I will move the thread to OutLook for developes for suitable support.

    The Visual C# discuss and ask the C# programming language, IDE, libraries, samples and tools . If you have some grammar or code errors, please feel free to contact us. We will try our best to give you a solution.

    Thanks for your understanding and cooperation.

    Best Regards,

    feih-7


    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.


    • Edited by Fei Hu Thursday, July 20, 2017 7:03 AM
    Thursday, July 20, 2017 7:01 AM
  • Hi Gary_MSDN,

    you had mentioned that ," if no attachment, it is working fine. If has attachment, Outlook client is not working."

    do you mean when you run the code and you not pass any argument in attachment or you pass empty string argument?

    if we pass empty string argument then it will give you an error that it is not able to find the path.

    I try to check with both.

    then I try to pass the attachment path and run the code.

    I find that it is working correctly on my side.

    I am using the Office 2016.

    I suggest you to repair your MS Office and try to install the latest updates may solve your issue.

    also let us know that which version of Outlook you are using.

    so that we can make a test with it.

    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, July 20, 2017 9:08 AM
    Moderator
  • Hi Deepak,

    Thanks for your reply.

    My Outlook version:

    Microsoft Office 365ProPlus

    version 1706 ( Build 8229.2086 Click-to-Run) 64-bit

    OS: windows 7 Enterprise (SP1) 64 bit

    From above image, you can see that attachment file has been past to Outlook client. Outlook client was launched and all data have been populated to it. It look like working fine, but all buttons in this page were not clickable, except top-right close button. You only can click top-right close button to close this Outlook client. When you click any where else, no response. 

    I installed my C# application in 3 computers (VM), one of them is working fine. two of them have this issue.

    In one computer with this issue, I restart computer, then this issue disappear. But after several days, it come back.

    I also do a lot of other test, I sent a lot of email without attachments from this C# application, then sent one email with attachment, suddenly it is working. But after some time, this issue come back. I don't know which trigger this issue, and it is not consistent. 

    Thanks

    Gary

    


    Gary Shi

    Thursday, July 20, 2017 1:30 PM
  • Hi Gary_MSDN,

    you had mentioned that , you had made a test on 3 different machines.

    I want to confirm with you that all 3 machines having same version of Outlook installed?

    you had mentioned that ,"I restart computer, then this issue disappear. But after several days, it come back."

    did you check that whether your machine get updated by any Windows or Office related updates?

    I can see that code is working correctly and it is possible that issue is related with specific OS or update.

    I can see that after creating mail you are displaying it.

    to avoid the issue , you can directly send the mail without displaying it.

    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, July 21, 2017 7:49 AM
    Moderator
  • Yes. 3 machines has same version of Outlook.

    If sending email directly without displaying Outlook client, it is working fine. But our application require Outlook client and user can modify email before sending it.

    After a lot of test, I guess it is Outlook bug. If I fellow bellow steps to send Outlook-Popup email with attachment, it will never has issues.

    1. restart machine

    2. launch Outlook client

    3. launch Our C# application and launch Outlook client from C# and send first email without attachment.

    After then, it is working fine and without any issue.It can send any email with attachment.

    Look like first time to launch Outlook client from C# has one initiation process and it is different for "with attachment" and "without attachment"

    Thanks


    Gary Shi

    Friday, July 21, 2017 4:01 PM
  • Hi Gary_MSDN,

    if you are available with Office insider then you can try to submit a feedback from there. because Office insider has an option to submit any bug related report to Microsoft.

    if you are not available with that then you can try to submit the issue to Outlook user voice.

    Outlook Feedback

    to work around this issue you can try to make a test with Windows 10 OS because I had check many times and with Windows 10 OS it is working correctly.

    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.

    • Marked as answer by Gary_MSDN Friday, July 28, 2017 1:25 PM
    Monday, July 24, 2017 5:20 AM
    Moderator
  • I will submit this one as bug. We have tested around 10 computers, 5 machines have this issue, others were fine. My temporary solution: Launch outlook twice. First Outlook client without attachment and shutdown immediate, then launch second Outlook client with attachment. Thanks.

    Gary Shi

    Friday, July 28, 2017 1:31 PM
  • Hi,

    try move ((Outlook._MailItem)mail).Display() between:

    Outlook.Application app = new Outlook.Application(); Outlook.MailItem mail = app.CreateItem(Outlook.OlItemType.olMailItem) as Outlook.MailItem;

    ((Outlook._MailItem)mail).Display();

    mail.Subject = Subject; 

    [...]

    ms

    • Marked as answer by Gary_MSDN Monday, November 27, 2017 9:01 PM
    Sunday, October 29, 2017 9:12 AM
  • Thanks. I will try to move this block code around. 

    Gary Shi

    Friday, November 17, 2017 7:26 PM
  • I change order and call Display() function immediately after creating mail obj. It fixed my issue. Thanks for help.

    Gary Shi

    Monday, November 27, 2017 9:04 PM