简体   繁体   中英

Open Outlook Application on the Client-side with an Attachment

I have trouble opening my outlook application(client) with an attached file from web server. Here's my code. Any suggestions?

        Dim app As Microsoft.Office.Interop.Outlook.Application
        Dim appNameSpace As Microsoft.Office.Interop.Outlook._NameSpace
        Dim memo As Microsoft.Office.Interop.Outlook.MailItem
        Dim processes = System.Diagnostics.Process.GetProcessesByName("OUTLOOK")
        Dim collCount As Integer = processes.Length

       If collCount > 0 Then
                app = Marshal.GetActiveObject("Outlook.Application")
                memo = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
                memo.Attachments.Add(Report, Outlook.OlAttachmentType.olByValue, , HttpContext.Current.Session("fileName"))
                memo.Display()
            Else
                Try
                    app = New Microsoft.Office.Interop.Outlook.Application
                    appNameSpace = app.GetNamespace("MAPI")
                    Process.Start("OUTLOOK")
                    memo = app.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
                    memo.Attachments.Add(Report, Outlook.OlAttachmentType.olByValue, , HttpContext.Current.Session("fileName"))
                    memo.Display()
                Catch ex As Exception
                    Debug.WriteLine(ex.Message)
                End Try
            End If

ASP.NET code is run on the server-side, so you should have at least Outlook installed there. Your code will never be run on the client-side.

I have trouble opening my outlook application(client) with an attached file from web server.

All current versions of Microsoft Office were designed, tested, and configured to run as end-user products on a client workstation. They assume an interactive desktop and user profile. They do not provide the level of reentrancy or security that is necessary to meet the needs of server-side components that are designed to run unattended.

Microsoft does not currently recommend, and does not support, Automation of Microsoft Office applications from any unattended, non-interactive client application or component (including ASP, ASP.NET, DCOM, and NT Services), because Office may exhibit unstable behavior and/or deadlock when Office is run in this environment.

If you are building a solution that runs in a server-side context, you should try to use components that have been made safe for unattended execution. Or, you should try to find alternatives that allow at least part of the code to run client-side. If you use an Office application from a server-side solution, the application will lack many of the necessary capabilities to run successfully. Additionally, you will be taking risks with the stability of your overall solution.

Read more about that in the Considerations for server-side Automation of Office article.

You can't - that code will run on the server, where nobody will see the message. And you cannot run Outlook on the server anyway.
Running on the client side is only possible from IE and only if your site is marked as trusted.

You can however create a MIME (EML) file and let the user download it from the browser - Outlook will be happy to open and display it. To make sure it is displayed as unsent, set the X-Unsent MIME header to 1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM