Results 1 to 3 of 3

Thread: vb code for Sending email using reportviewer via Ms-outlook 2007

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    3

    vb code for Sending email using reportviewer via Ms-outlook 2007

    I have created a following vb-code for Sending email message to recipients, but it showing error as - 'CreateItem' is not a member of 'System.Windows.Forms.Application' and 'Session' is not a member of 'System.Windows.Forms.Application'. Please help to get rid of this error..Thanks in Advance

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    SendEmail()
    End Sub

    Private Sub SendEmail()
    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.Attachments.Add("c:\Daily Diesel Consumption Truck.xls", _ Outlook.OlAttachmentType.olByValue)
    mail.Send()
    End If
    End Sub

    ..........................

    Actually I want to add that "Email" Tab in ReportViewer where I can send email with attachement file ... Please guide me...Thanks again.

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: vb code for Sending email using reportviewer via Ms-outlook 2007

    Where did you copy that code from? It appears to have been intended for an Outlook add-in. Are you specifically trying to automate Outlook or do you just want to send an email because, if it's the latter, you should be using an SmtpClient object.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2017
    Posts
    3

    Re: vb code for Sending email using reportviewer via Ms-outlook 2007

    Quote Originally Posted by jmcilhinney View Post
    Where did you copy that code from? It appears to have been intended for an Outlook add-in. Are you specifically trying to automate Outlook or do you just want to send an email because, if it's the latter, you should be using an SmtpClient object.
    Actually, I had no idea how to implement or design my object via code, so I tried the code from outside but no idea or meaning of that at all, i got puzzled with errors as I m very new in writing VB-Code...So please help me to have an idea to implement my object that is simply I want a tab of "Email" option in my Reportviewer/.rdlc file ( such as Print or Save/Export) by which I can send email with attachment file.... I m not sure for that whether SmtpClient object is the best option or I can bind/import my Outlook-Application for doing the same...

    Thanks once again for guiding me...

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width