Jump to content
samesdavis

Enviar email Outlook qualquer versão Office

Recommended Posts

samesdavis

Olá pessoal,

Tenho um sistema que roda em vários micros e cada um deles com versões diferentes do office.

O meu código não está dando certo, segue

referenciei o outlook e usei o imports

Imports Microsoft.Office.Interop

    Private Sub btnEnviar_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnEnviar.Click
        Cursor.Current = Cursors.WaitCursor
        Try
            Dim tempApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application
            'Dim tempApp = GetObject(, "Outlook.Application")
            Dim tempNS As Outlook.NameSpace
            Dim MailFolder As Outlook.MAPIFolder
            tempNS = tempApp.GetNamespace("MAPI")
            tempNS.Logon(, , True, True)

            Dim newMail As Outlook.MailItem = Nothing
            MailFolder = tempNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderOutbox)
            newMail = MailFolder.Items.Add(Outlook.OlItemType.olMailItem)
            With newMail
                .To = txtPara.Text
                .Subject = txtAssunto.Text
                .Body = txtMensagem.Text
                .Send()
            End With
            newMail = Nothing
            MailFolder = Nothing
            tempNS = Nothing
            tempApp = Nothing

            DialogResult = DialogResult.Yes
        Catch ex As Exception
            MsgBox(ex.ToString())
            DialogResult = DialogResult.No
        Finally
            Cursor.Current = Cursors.Default
        End Try

    End Sub

se eu usar essa linha

Dim tempApp As Microsoft.Office.Interop.Outlook.Application = New Microsoft.Office.Interop.Outlook.Application

ele só funciona no office2007

se eu usar essa linha, ele dá a mensagem de que não posso criar objeto activex

Dim tempApp = GetObject(, "Outlook.Application")

o que faço ?

 

 

 

 

Share this post


Link to post
Share on other sites
samesdavis

Usei a linha

Dim tempApp = CreateObject("Outlook.Application")

Funcionou, porém só funciona se o Outlook estiver fechado, se estiver aberto, ele mostra uma mensagem de erro.

no caso eu teria que fazer um loop nos processos abertos, fechar as instancias do outlook e abrir essa nova

e no final fechar essa nova também.

 

 

Share this post


Link to post
Share on other sites
winseelan

Hello Sam,

Im facing the same issue, may i know how did you resolve this issue? could you please ellabrate little bit more?

thank you

jey

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.