simple e-mail application using microsoft exchange objects

Posted on 2007-08-06
Last Modified: 2013-11-05
I am writing an application that I need to write an e-mail script in visual basic. Because everyone uses Microsoft Exchange in our shop, I was hoping that someone could show me a snippet of code that I can pass an e-mail address to using the outlook objects and throw together an e-mail rather quickly and send out.

Thanks in advance.
Question by:samic400
    1 Comment
    LVL 53

    Accepted Solution

    using Outlook Object Library

    Private Sub Send_Mail()
      Dim iOutlook As Outlook.Application
      Dim myApp As Outlook.MailItem
      Set iOutlook = New Outlook.Application
      Set myApp = iOutlook.CreateItem(olMailItem)
      temp = "ryancys"
      txtMessage = "Hello "
      AttachFile = "C:\file.txt"
      myApp.To = ""
      myApp.Subject = "Hello "
      myApp.Attachments.Add AttachFile
      myApp.Body = "Hi " & temp & vbCrLf & vbCrLf & txtMessage
      'myApp.HTMLBody = ""
      'Do While iOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderOutbox).Items.Count <> 0
      '    DoEvents
      MsgBox "Successfully Sent", vbInformation, "Email Sent"
    End Sub

    Other usefull link

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
    Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

    731 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now