locked
MAPI Freezes RRS feed

  • Question

  • I'm currently using the MAPI library found here: http://www.codeproject.com/KB/IP/SendFileToNET.aspx.

    While it works fine in opening an instance of Outlooks "New Message", it freezes in term of not being able to access the body of the message, or any other fields for that matter.

    They do offer how the freezing can stop, and that's by using threads. I implemented the recommended change. But now, instead of getting a frozen outlook window, I get a "General MAPI error[2]" when I call. Below is my code:

    private Thread actionThread;
    private ThreadStart startActionThread;
    private void tsbEmail_Click(object sender, EventArgs e)
    {
         try
         {
              startActionThread = new ThreadStart(SendMail);
              actionThread = new Thread(startActionThread);
              actionThread.Start();
         }
         catch (Exception ex)
         {
              MessageBox.Show("Error sending message\n" + ex.StackTrace, "Error during email");
         }
    }

    private void SendMail()
            {
                try
                {
                    if (!AppSettings.IsTrial)
                    {
                        string tfile = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
                        tfile += "\\shot_" + DateTime.Now.Ticks + ".png";
                        Bitmap bm =
                            new Bitmap(daMain.Picture, new Size(daMain.Width, daMain.Height));
                        bm.Save(tfile, ImageFormat.Png);
                        MAPI mapi = new MAPI();
                        mapi.AddAttachment(tfile);
                        mapi.SendMailPopup("Subject", "body");
                        this.WindowState = FormWindowState.Normal;
                    }
                }
                catch (Exception ex)
                {
                }
                finally
                {
                    actionThread.Abort();
                    actionThread.Join();
                }
            }

    The code for the MAPI class is found in the link that I posted at the beginning of this post.

    Any help would be greatly valued.

    Cheers,
    • Moved by Harry Zhu Friday, August 21, 2009 2:34 AM (From:Visual C# General)
    Wednesday, August 19, 2009 6:51 PM

Answers