Using Outlook via VB.NET

Hi Everybody,
I would like to explain one of faq within this essay , how we can
use Outlook functions  
via VB.NET Windows Application. 
I am going to explain it with VB.NET 2010.

If any question, please feel free to contact me y_turkeli@yahoo.com or

1-) We are creating a new Windows Application Project

2-) We are designing this windows form in a similar way to the picture below

3-) We are writing this code

Imports Microsoft.Office.Interop.Outlook
Public Class Form1

    Private Sub send_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles send_btn.Click
        Dim my_outlook As New Microsoft.Office.Interop.Outlook.Application()
        Dim my_namespace As Microsoft.Office.Interop.Outlook.NameSpace
        Dim my_folder As Microsoft.Office.Interop.Outlook.MAPIFolder

        my_namespace = my_outlook.GetNamespace("MAPI")

        Dim my_mail As Microsoft.Office.Interop.Outlook.MailItem


        my_folder = my_namespace.GetDefaultFolder(Microsoft.Office.Interop.Outlook.OlDefaultFolders.olFolderOutbox)

        my_mail = my_folder.Items.Add(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)

        my_mail.Subject = "From Outlook"
        my_mail.Body = text_txt.Text
        my_mail.To = to_txt.Text
        my_mail.CC = cc_txt.Text

    End Sub
End Class

4-) Lets run the application

4-) Please allow your program to send email

5-) Check your email box 

Have a nice day
Yener Turkeli

No comments:

Post a Comment