Skip to content

mandar correo outlook desde VB.NET

November 29, 2012

Una forma muy senzilla de mandar correos electrónicos  a través de Outlook mediante una aplicación VB.Net es esta:

Añadir la referencia COM /  Microsoft Outlook 12.0 Object Library

Imports System.Runtime.InteropServices
Imports Outlook = Microsoft.Office.Interop.Outlook
Imports Microsoft.Office.Core
Imports System.Reflection
Imports Microsoft.Win32

   Private Sub enviaCorreu()

        Dim oApp As Outlook._Application
        oApp = New Outlook.Application()

        Dim oMsg As Outlook._MailItem
        oMsg = oApp.CreateItem(Outlook.OlItemType.olMailItem)
        oMsg.Subject = “Cabecera del mensaje “
        oMsg.Body = “Cuerpo del mensaje” & vbCr & vbCr

        oMsg.To = “usuario1@servidor.com; usuario2@servidor.com; usuario3@servidor.com”

        ‘Dim sSource As String = “C:\Temp\ejemplo.txt”
        ‘Dim sDisplayName As String = “ejemplo.txt”
        Dim sBodyLen As String = oMsg.Body.Length
        ‘Dim oAttachs As Outlook.Attachments = oMsg.Attachments
        ‘Dim oAttach As Outlook.Attachment

        ‘oAttach = oAttachs.Add(sSource, , sBodyLen + 1, sDisplayName)
        oMsg.Send()
        ‘oApp = Nothing
        ‘oMsg = Nothing
        ‘oAttach = Nothing
        ‘oAttachs = Nothing

    End Sub

About these ads

From → VB.NET y Office

Leave a Comment

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

%d bloggers like this: