Link to home
Start Free TrialLog in
Avatar of JeffMCC
JeffMCCFlag for United States of America

asked on

How to send email from VB 2015 using Outlook?

I am trying to send e-mail from a 2015 VB app and am having trouble.  I have basically copied code from the MSDN web site for VB 2013 and later.  I could not find 2015 specific code.

The problem I have is  .CreateItem nor .Session are members of Application.  I fell like I have left something out, but not sure what.

I have added as references Microsoft Office 10. Object Library and Microsoft Outlook 15.0 Object Library.
I have included the import in my project.
   Imports Outlook = Microsoft.Office.Interop.Outlook



    
Private Sub SendSalesReport()
        Dim mail As Outlook.MailItem = CType(Application.CreateItem(
            Outlook.OlItemType.olMailItem), Outlook.MailItem)
        mail.Subject = "Quarterly Sales Report FY06 Q4"
        Dim currentUser As Outlook.AddressEntry =
            Application.Session.CurrentUser.AddressEntry
        If currentUser.Type = "EX" Then
            Dim manager As Outlook.ExchangeUser =
                currentUser.GetExchangeUser().GetExchangeUserManager()
            ' Add recipient using display name, alias, or smtp address
            mail.Recipients.Add(manager.PrimarySmtpAddress)
            mail.Recipients.ResolveAll()
            mail.Send()
        End If
    End Sub

Open in new window

Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Try changing Application to Outlook.Application
Avatar of JeffMCC

ASKER

@Najam,

I tried changing to Outlook.Application.  I now get Reference to non-shared member requires an object reference.
Avatar of JeffMCC

ASKER

@Eric,

I'll take a look at that, but was hoping to get this method working.

Thanks
That issue that solved by making
Private Sub SendSalesReport() 

Open in new window

to
Public Shared Sub SendSalesReport()

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of ktaczala
ktaczala
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of JeffMCC

ASKER

@Najam,

That still did not work.  Same message.

@ktaczala,

That worked.  Thanks