Jump to content

Elegir cuenta de correo de outlook


Recommended Posts

Hola, estoy intentando enviar un correo pero no con la cuenta predeterminada que tengo en outlook. He revisado la ayuda y creo que lo que pretendo hacer se realiza atraves de la propiedad SendUsingAccount

Dim objOutlook As Object
Dim objItem As Object
Dim ADJUNTO As Variant
Set objOutlook = CreateObject("Outlook.Application")
Set objItem = objOutlook.CreateItem(olMailItem)
Set objNameSpace = objOutlook.GetNamespace("MAPI")
With objItem
.To = Range("K1").Value
.Subject = Range("A25").Value
.SendUsingAccount = "user@yahoo.es"
.Display
End With

No logro hacerlo funcionar, siempre me pone la cuenta por defecto.

Este es el link de esta propiedad que viene en la ayuda.

Propiedad MailItem.SendUsingAccount (Outlook)

Gracias.

Link to comment
Share on other sites

  • 2 weeks later...

Aunque esta consulta ya quedó solucionada en el foro antiguo, me ha parecido interesante que quedera constancia de la solución.

Sub EnviarCorreo()
Dim Aplicación As Outlook.Application
Dim Correo As Outlook.MailItem
Set Aplicación = CreateObject("Outlook.Application")
Set Correo = Aplicación.CreateItem(olMailItem)
Cuenta = ObtenerCuenta(Aplicación, "toldeman@toldeman.com")
With Correo
   .To = Range("K1").Value
   .Subject = Range("A25").Value
   .SendUsingAccount = Aplicación.Session.Accounts.Item(Cuenta)
   .Display
End With
End Sub

Function ObtenerCuenta(Aplicación As Object, EmailAddress As String)
For Each oAccount In Aplicación.Session.Accounts
    If oAccount.AccountType = olPop3 And _
       oAccount.SmtpAddress = EmailAddress Then
       ObtenerCuenta = oAccount
       Exit For
    End If
Next
End Function

 

Link to comment
Share on other sites

  • 1 year later...

Buenos días,

uso exactamente el código que has expuesto, pero me da error en la segunda linea, se detiene en "Dim aplicación as Outlook.Application" mostrando el mensaje "no se ha definido el tipo definido por el usuario" (ver imagen).

Me podeís ayudar con este error? Muchas gracias.

HolaCaptura.thumb.JPG.c7debe6827ba731f46fbbc5fd4f20d3c.JPG

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

Privacy Policy