简体   繁体   中英

How to open Outlook 2016 with vs2017

I've on my computer Office 2013 32bits. I develop an Intranet but on server and windows session of my customer : it's an Office 2016 32bits... On my vs2017 I install with nugget package microsoft.office.interop 15.0.4797.1003 But it's for Office 2013. I create mail with

dim outl as new outlook.application
dim Mai las outl.mailitem=outl.createItem(Micrososft.office.Interop.outlook.olitemtype.olmailItem)
Mail.To=...
...
Mail.attachment.add(MyFile)
Mail.display()

I try to put my code on the customer server, and like I thougth ... 80070005 Access denied... I don't find how to open an Outlook 2016 Thanks for your help

UPDATE On Property of my project, I've "Any CPU" option activate

Finally... A friend says me, my method can be ok only If I open session on server. outlook.display run on server not on clientside on other computer. Then I change my mind and build a emml file, store and push with ashx file

 For Each _file As String In IO.Directory.GetFiles(IO.Path.GetDirectoryName(Path), "*.eml")
                        IO.File.Delete(_file)
                    Next

                    Dim MailMdp As New Net.Mail.MailMessage
                    MailMdp.Subject = Vers.Devi.Libelle
                    MailMdp.From = New Net.Mail.MailAddress(ConnectedUser.Mail)

                        MailMdp.To.Add(AnAdress)

                    MailMdp.Body = "Bonjour,"
                    Dim att As New Net.Mail.Attachment(Path)
                    MailMdp.Attachments.Add(att)
                    MailMdp.IsBodyHtml = True

                    Dim Client As Net.Mail.SmtpClient = New Net.Mail.SmtpClient()
                    Client.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.SpecifiedPickupDirectory
                    Client.PickupDirectoryLocation = IO.Path.GetDirectoryName(Path)
                    Client.Send(MailMdp)

                    Dim MonEml = IO.Directory.GetFiles(IO.Path.GetDirectoryName(Path), "*.eml", IO.SearchOption.TopDirectoryOnly).First

                    Dim fso As New System.IO.FileInfo(MonEml)
                    Dim NomFichier As String = fso.Name
                    context.Response.Clear()
                    context.Response.ClearContent()
                    context.Response.ClearHeaders()
                    context.Response.ContentType = "message/rfc822"
                    context.Response.AppendHeader("Content-Disposition", "attachment; filename=" & NomFichier)
                    context.Response.TransmitFile(MonEml)
                    context.Response.End()

I hope that can be helpfull

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