JeffMCC
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.O utlook
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.O
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
I prefer to use a late-bound method like this one: http://www.codeproject.com/Articles/17561/Programmatically-adding-attachments-to-emails-in-C
Try changing Application to Outlook.Application
ASKER
@Najam,
I tried changing to Outlook.Application. I now get Reference to non-shared member requires an object reference.
I tried changing to Outlook.Application. I now get Reference to non-shared member requires an object reference.
ASKER
@Eric,
I'll take a look at that, but was hoping to get this method working.
Thanks
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()
to Public Shared Sub SendSalesReport()
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Najam,
That still did not work. Same message.
@ktaczala,
That worked. Thanks
That still did not work. Same message.
@ktaczala,
That worked. Thanks