simple e-mail application using microsoft exchange objects

Posted on 2007-08-06
Medium Priority
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

Dhaest earned 2000 total points
ID: 19639279
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 = "me@here.com"
  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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

839 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