Doubt with the Sender command of VBA excel Outlook objects

Asked

Viewed 313 times

1

I have an excel VBA code, which sends to some specific recipients some e-mail’s, but at first these email as they are being sent by my outlook are coming out with my name, but in Outlook we have the option to type from which name you want to send this e-mail that is the "DE" field. My doubt and, as I put in the code for him to send from another name, through this field "OF", without being by my name? Searching I found the Sender command, but when I use it gives the message "Compile Error - Incompatible Types". Below sege the code line for sending email, can help me please.

Sub Enviar_e_mail()

Dim OutApp As Outlook.Application
Dim OutMail As Outlook.MailItem
'Criação e chamada do Objeto Outlook
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(olMailItem)
Application.DisplayAlerts = False

With OutMail
.Sender = "[email protected]"
.To = "[email protected]"
'.CC = ""
.BCC = ""
.Subject = "Titulo do e-mail"
.Body = "Texto do E-mail"
'O trecho abaixo anexa a planilha ao e-mail
.Attachments.Add "Arquivo a ser anexado"
.Send
End With

1 answer

2

I use a code like the following to send emails here at work:

Set oMensagem = CreateObject("CDO.Message")
Set oConfiguração = CreateObject("CDO.Configuration")

oConfiguração.Load -1 'Padrões CDO
Set vFields = oConfiguração.Fields

With vFields
  .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.***.com.br"

  .Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

  .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "***@***.com.br"
  .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "SENHA"
  .Update
End With

With oMensagem

  Set .Configuration = oConfiguração
  .to = PARA
  .CC = COM_COPIA
  .BCC = COM_COPIA_OCULTA
  .From = "***@***.com.br"
  .ReplyTo = "suporte@***.com.br"
  .Subject = ASSUNTO
  .AddAttachment (MyFile)
  .HTMLBody = TEXTO & ASSINATURA
  .Send

End With

I only cut the sections that define the variables used...

Browser other questions tagged

You are not signed in. Login or sign up in order to post.