blog

Home / DeveloperSection / Blogs / Open outlook message window in wpf

Open outlook message window in wpf

Vijay Shukla7441 16-Aug-2013

Open outlook message window in wpf

In this blog I am trying to explain the concept of how can I open outlook message window in wpf.

You can firstly add the reference of Microsoft.Office.Interop.Outlook for add reference in solution explorer and then create a simple UI like below image:-


Open outlook message window in wpf

Open outlook message window in wpf

.xaml code:

<Window x:Class="wpfMailClient.MainWindow"

        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

        Title="MainWindow" Height="350" Width="525">

    <Grid>

        <Button Content="btnSend" Height="23" HorizontalAlignment="Left" Margin="416,252,0,0" Name="button1" VerticalAlignment="Top" Width="75" Click="button1_Click" />

        <TextBox Height="23" HorizontalAlignment="Left" Margin="111,25,0,0" Name="txtEmail" VerticalAlignment="Top" Width="380" />

        <TextBox Height="23" HorizontalAlignment="Left" Margin="111,54,0,0" Name="txtSubject" VerticalAlignment="Top" Width="380" />

        <Label Content="Email" Height="28" HorizontalAlignment="Left" Margin="40,21,0,0" Name="lblEmail" VerticalAlignment="Top" />

        <Label Content="Subject" Height="28" HorizontalAlignment="Left" Margin="40,50,0,0" Name="lblSubject" VerticalAlignment="Top" />

        <TextBox Height="157" HorizontalAlignment="Left" Margin="111,88,0,0" Name="txtBody" VerticalAlignment="Top" Width="380" />

    </Grid>

</Window>

.cs Code:-

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Windows;

using System.Windows.Controls;

using System.Windows.Data;

using System.Windows.Documents;

using System.Windows.Input;

using System.Windows.Media;

using System.Windows.Media.Imaging;

using System.Windows.Navigation;

using System.Windows.Shapes;

namespace wpfMailClient

{

    ///<summary>

    /// Interaction logic for MainWindow.xaml

    ///</summary>

    publicpartialclassMainWindow : Window

    {

        public MainWindow()

        {

            InitializeComponent();

        }

        privatevoid button1_Click(object sender, RoutedEventArgs e)

        {

           Microsoft.Office.Interop.Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();

            Microsoft.Office.Interop.Outlook.MailItem message =

            (Microsoft.Office.Interop.Outlook.MailItem)outlookApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);

            message.Subject = "Testing Mail!";

            message.Recipients.Add("some@email.com");

            message.Body = "Hello. This is body area, write your mail here.";

            message.Display(false);

        }

    }

}


Updated 18-Sep-2014

Leave Comment

Comments

Liked By