how to send an email with outlook in windows 10 from an app in c #

0

I'm doing an app in windows 10 that sends emails through outlook, for that I'm using the library Microsoft Outlook 15.0 Object Library, the problem is that I can not link outlook to the application, this is the code to send it

private void enviarCorreoOutlook(string cuerpo, string destinatario)
        {
            try
            {
                var oApp = new Microsoft.Office.Interop.Outlook.Application();
                Microsoft.Office.Interop.Outlook.NameSpace ns = 
              oApp.GetNamespace("MAPI");
                var f =ns.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderInbox);
                System.Threading.Thread.Sleep(1000);
                var mailItem = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
                Microsoft.Office.Interop.Outlook.Attachment att = mailItem.Attachments.Add(      
                imageSignaturePath,
                Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem,
                null,
                "Firma");



                mailItem.Subject = textBox1.Text.ToString();
                mailItem.HTMLBody = "<body>"+cuerpo+"</body>";
                mailItem.To = destinatario;
                mailItem.Send();
            }



            catch (System.Exception e)
            {
                MessageBox.Show("No se ha podido enviar el correo a: "+destinatario);
            }
    
asked by luiso 16.05.2018 в 11:05
source

0 answers