Inclusion d’images dans un courrier électronique Outlook

J’essaie d’utiliser un document Microsoft Word en tant que corps d’un courrier électronique Microsoft Outlook. Jusqu’à présent, j’ai pu inclure le texte d’un fichier .docx dans le corps de l’e-mail avec le code:

if (File.Exists(fileName.ToSsortingng())) { DateTime today = DateTime.Now; object readOnly = false; object isVisible = false; //Set Word to invisible wordApp.Visible = false; //Open the word document aDoc = wordApp.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible, ref missing, ref missing, ref missing, ref missing); try { //Activate Document aDoc.Activate(); //Find Place Holders and replace them with values this.FindAndReplace(wordApp, "", NameAddressed); this.FindAndReplace(wordApp, "", SessionInfo); this.FindAndReplace(wordApp, "", GuestNumber); this.FindAndReplace(wordApp, "", Balance); //Postal this.FindAndReplace(wordApp, "", FullName); this.FindAndReplace(wordApp, "", Address1); if (Address2 != "&nbsp" && Address2 != "" && Address2 != " ") this.FindAndReplace(wordApp, "", Address1 + "\n\r" + Address2); else this.FindAndReplace(wordApp, "", Address1); this.FindAndReplace(wordApp, "", City); this.FindAndReplace(wordApp, "", State); this.FindAndReplace(wordApp, "", Zip); } catch (Exception ex) { aDoc.Close(ref missing, ref missing, ref missing); ClientScript.RegisterStartupScript(this.GetType(), "error", "javascript:;alert('" + ex.Message + "')"); return false; } aDoc.SaveAs(ref saveAs); //Save the file as the correct file name if (DataType.Text == "Email") { Outlook.Application oApp = new Outlook.Application(); // Create a new mail item. Outlook.MailItem eMail = (Outlook.MailItem)oApp.CreateItem(Outlook.OlItemType.olMailItem); Word.Range r = aDoc.Content; r.Select(); ssortingng s = r.Text; eMail.Subject = "Confirmation Email"; eMail.To = "[email protected]"; eMail.Body = s; ((Outlook._MailItem)eMail).Send(); //Close the document - you have to do this aDoc.Close(ref missing, ref missing, ref missing); } litError.Text = "File Created. "; return true; } else { litError.Visible = true; litError.Text = "File Does Not Exist"; return false; } 

Mais ce code n’inclura pas les images qui figurent également dans le document Word dans le courrier électronique. Le fichier .docx peut-il également envoyer ses images dans Outlook et conserver son format d’origine? Merci d’avance

Tout d’abord, vous définissez la propriété MailItem.Body texte MailItem.Body . Deuxièmement, créez une pièce jointe et définissez la propriété PR_ATTACH_CONTENT_ID (nom DASL "http://schemas.microsoft.com/mapi/proptag/0x3712001F" ) à l’aide de Attachment.PropertyAccessor.SetProperty .

Votre corps HTML (propriété MailItem.HTMLBody ) devra alors faire référence à cette pièce jointe d’image via l’atsortingbut cid:

  

où xyz est la valeur de la propriété PR_ATTACH_CONTENT_ID .

Examinez un message existant avec OutlookSpy (cliquez sur le bouton IMessage).

EDIT: exemple de script (par coeur):

 attachment = MailItem.Attachments.Add("c:\temp\MyPicture.jpg") attachment.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "MyId1") MailItem.HTMLBody = "Test image "