How to send simple mail from windows form....

Posted on 2008-11-19
Medium Priority
Last Modified: 2013-12-17

I want to send a simple mail from my windows app using Outlook.Application but the outlook app will not start ???

Can somone show me how i can send a simple mail from windows form by using outlook
private void SendTransactionByEmail()
            Microsoft.Office.Interop.Outlook.Application outLookApp = new Microsoft.Office.Interop.Outlook.Application();
            // Create the mail message
            Microsoft.Office.Interop.Outlook.MailItem mailItem = (MailItem)outLookApp.CreateItem(OlItemType.olMailItem);
            mailItem.Subject = "some subject goes here";
            mailItem.BodyFormat = OlBodyFormat.olFormatHTML;
            mailItem.Body = "email body goes here"; 

Open in new window

Question by:Adnan
  • 2

Author Comment

ID: 22992624
i want to Open outlook message window...?!

Accepted Solution

Adnan earned 0 total points
ID: 22992663

You can open the outlook window by this code...

Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
            Microsoft.Office.Interop.Outlook.MailItem oMsg = (MailItem)oApp.CreateItem(OlItemType.olMailItem);
                Microsoft.Office.Interop.Outlook.Recipient oRecip;

                //Then for every recipient you want to add:

                oRecip = (Microsoft.Office.Interop.Outlook.Recipient)oMsg.Recipients.Add("test@test.com");

                //Then use this call to display the message window:

                //Finally, remember to set all objects to null once you are done:

                oRecip = null;
                oMsg = null;
                oApp = null;

Expert Comment

ID: 23243875
thanks for the post, i modified the code to work for me in Visual Basic .NET, e.g. :
    Private oApp As New Microsoft.Office.Interop.Outlook.Application
    Private oMsg As Microsoft.Office.Interop.Outlook.MailItem
    Private oRecip As Microsoft.Office.Interop.Outlook.Recipient
    Private Sub PrePrepareEmail()
        oMsg = oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem)
        oRecip = oMsg.Recipients.Add("test@test.com")
    End Sub
    Private Sub WheneverLater()
        oApp = Nothing
        oMsg = Nothing
        oRecip = Nothing
    End Sub

Open in new window


Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
High user turnover can cause old/redundant user data to consume valuable space. UserResourceCleanup was developed to address this by automatically deleting user folders when the user account is deleted.
Integration Management Part 2
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

830 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