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?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

AdnanAuthor Commented:
i want to Open outlook message window...?!
0
AdnanAuthor 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.