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

Hi

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

AdnanAsked:
Who is Participating?
 
AdnanConnect With a Mentor Author Commented:
I MADE IT....

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");
                oRecip.Resolve();

                //Then use this call to display the message window:
                oMsg.Display(true);

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

                oRecip = null;
                oMsg = null;
                oApp = null;
0
 
AdnanAuthor Commented:
i want to Open outlook message window...?!
0
 
KristjanLaaneCommented:
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")
        oRecip.Resolve()
        oMsg.Display(True)
    End Sub
 
    Private Sub WheneverLater()
        oApp = Nothing
        oMsg = Nothing
        oRecip = Nothing
    End Sub

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.