C# Outlook send email with embedded image without using wordeditor
===

I am having troubles sending email with embedded image. I tried some solutions using word editor but they can't solve my circumstances. I can't use SmtpClient becuase a client does not want it. He has exchange and needs to have sent email in sent folder.

I want send an email in html format with eg. image in header - logo and image in footer - sign.

I have and HTML template stored in database as string to provide more looks and purposes of an email. Specific data I insert using variables which are replaced in moment of sending.

Does anyone know how to add image stored in database to email into <img src="cid:myimageid" /> without using mailitem.wordeditor and without need to display inspector? Let's assume the images are already on disc or can be a stream somehow used?

My application needs send in background without notify the user by another windows. Adding images using wordeditor needs to have inspector displayed. And even when I immediately close it, it blinks.

The second trouble is how to format HTMLBody property of mailitem, when it does not accept normal HTML but only their so-called html. Is it really needed to study their word html?

Firstly I used MailMessage and this template worked even with images and alternativeviews. Maybe exist some posibility to use MailMessage to send it via outlook, but I dont know it.

Does anoyne came accross with it?

        public void SendEmailViaOutlook()
        {
            //in template I mostly need to use table and css to divide email into blocks - header, content, footer

            String htmlTemplate = "<html>\n";
            htmlTemplate += "  <head>\n";
            htmlTemplate += "    <style type=\"text//css\">\n";
            htmlTemplate += "       #Header  {border-width: 1; border: solid; text-align: center}\n";
            htmlTemplate += "       #Content {border-width: 1; border: solid; text-align: center}\n";
            htmlTemplate += "       #Footer   {border-width: 1; border: solid; text-align: center}\n";
            htmlTemplate += "    </style>\n";
            htmlTemplate += "  </head>\n";
            htmlTemplate += "  <body>\n";
            htmlTemplate += "    <table>\n";
            htmlTemplate += "      <tr><td><img src=\"cid:companylogo\"/></td></tr>\n";
            htmlTemplate += "      <tr><td><div id=\"Header\">$HEADER$</div></td></tr>\n";
            htmlTemplate += "      <tr><td><div id=\"Contentr\">$CONTENT$</div></td></tr>\n";
            htmlTemplate += "      <tr><td><div id=\"Footer\">$FOOTER$</div></td></tr>\n";
            htmlTemplate += "      <tr><td><img src=\"cid:usersign\"/></td></tr>\n";
            htmlTemplate += "    </table>\n";
            htmlTemplate += "  </body>n";
            htmlTemplate += "</html>\n";

            //the code is simplified to demostrate problem
            //$CONTENT etc. will be replaced by another html from custom html wysiwyg editor

            try
            {
                Outlook.Application outlook = new Outlook.Application();
                Outlook._MailItem outLookMailMessage = outlook.CreateItem(Outlook.OlItemType.olMailItem) as Outlook._MailItem;
                outLookMailMessage.BodyFormat = Outlook.OlBodyFormat.olFormatHTML;

                /*

                here a I have problem to set the property - my template is not
                set and a blank email is sent - almost none html it takes except the example from msdn http://support.microsoft.com/kb/310262, are there some rules how to write it?

                */

                outLookMailMessage.HTMLBody = htmlTemplate;
                outLookMailMessage.Subject = this.Subject;

                outLookMailMessage.Recipients.Add("somenone@somewhere.com");

                /*
                 here I woud need somehow link 2 images with cid companylogo and usersign
                 */

                outLookMailMessage.Send();
                outLookMailMessage = null;
            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

Any help would be much appreciated!