I have a management program with which a file sent by mail, the party of running the outlook is great, but when teams do not have outlook express and have only broken and that I have to check if there is me outlook mapi and only use, but that does not go.
Code:
Private Sub Enviar_mail()
'comprobar si esta outlook o outlook express
Dim fallo As Boolean = False
Dim Objeto As Object
' Crea una referencia al objeto
Try
Objeto = CreateObject("Outlook.Application")
Catch ex As OleDbException
fallo = True
End Try
' No dío error
If fallo = True Then
Dim fila As DataRowView
Dim STRCod As String
For Each fila In Me.List_Proyecto.SelectedItems
STRCod = fila.Item(2)
AxMAPIMessages1.AttachmentName = STRCod
AxMAPIMessages1.AttachmentPathName = ruta & "Archivos\" & Me.ComboCliente.Text & "\" & STRCod
Next
'lo mandamos con outlook express
AxMAPISession1.SignOn()
With AxMAPIMessages1
WithMAPIMessages()
.MsgIndex = -1
.RecipDisplayName = ""
.MsgSubject = ""
.MsgNoteText = ""
.SessionID = AxMAPISession1.SessionID 'MAPISession.SessionID
.ResolveName()
.AttachmentIndex = 0
.AttachmentPosition = 0
.AttachmentType = 0
'.Send()
End With
AxMAPISession1.SignOff()
Else
'Crear una aplicación Outlook.
Dim oApp As Microsoft.Office.Interop.Outlook.Application
oApp = New Microsoft.Office.Interop.Outlook.Application()
' Crear un nuevo elemento de correo.
Dim oMsg As Microsoft.Office.Interop.Outlook._MailItem
oMsg = oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
oMsg.Body = "" & vbCr & vbCr
Dim fila As DataRowView
Dim STRCod As String
Dim sBodyLen As String = oMsg.Body.Length
Dim oAttachs As Microsoft.Office.Interop.Outlook.Attachments = oMsg.Attachments
Dim oAttach As Microsoft.Office.Interop.Outlook.Attachment
For Each fila In Me.List_Proyecto.SelectedItems
STRCod = fila.Item(2)
oAttach = oAttachs.Add(ruta & "Archivos\" & Me.ComboCliente.Text & "\" & STRCod, , sBodyLen + 1, )
'' Abrir mensaje nuevo
oMsg.Display()
End If
End Sub
Comment