2012-12-18 127 views
1

我有以下代码:嵌入图片Outlook电子邮件身体

string imageSrc = "C:\\Documents and Settings\\menonsu\\Desktop\\screenScrapper\\Bitmap1.bmp"; 
oMsg.HTMLBody = "<HTML><BODY><img src = \" cid:[email protected] \"/><br><font size=\"2\" face=\"Courier New\">" + introText + "</font>" + body + "<font size=\"2\" face=\"Courier New\">" + conclText + "</font>" + " </BODY></HTML>"; 

Microsoft.Office.Interop.Outlook.Attachment attc = oMsg.Attachments.Add(imageSrc, Microsoft.Office.Interop.Outlook.OlAttachmentType.olEmbeddeditem, null, ""); 
      attc.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001E", "[email protected]"); 

//Send the message. 
oMsg.Save(); 

出于某种原因,邮件仅仅是表示X当我尝试运行此代码...任何人都知道为什么吗?

回答

3

从我可以告诉你,你没有正确设置内容ID。尝试将代码更改为以下内容:

attc.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x370E001F", "image/bmp"); 
attc.PropertyAccessor.SetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F", "[email protected]"); 

我已经做了一些改动。我内置的图像在一些电子邮件,我不得不从我的web应用程序发送的system.net.mail

System.Net.Mail.LinkedResource theContent = new System.Net.Mail.LinkedResource({path to image}); 
theContent.ContentID = "TheContent"; 

String altViewString = anEmail.Body.replace("{original imageSource i.e. '../Images/someimage.gif'}","cid:TheContent"); 

System.Net.Mail.AlternateView altView = System.Net.Mail.AlternateView.CreateAlternateViewFromString(altViewString, Nothing, System.Net.Mime.MediaTypeNames.Text.Html); 

altView.LinkedResources.add(theContent); 

anEmail.Message.AlternateViews.Add(altView); 
+0

甜蜜......它的工作原理谢谢 – user1753675

+0

出于好奇,你使用了哪一部分? setProperty修改或邮件库? –

+0

如何从消息中使用C#或PowerShell下载嵌入式图像(嵌入式图像)? – Kiquenet

1

使用“备用视图”这里有一个简单的解决方案:

private static void insertPictureAsLink(Outlook.MailItem mail, String imagePath, String URI) 
    { 
     mail.BodyFormat = OlBodyFormat.olFormatHTML; 
     mail.HTMLBody += String.Format("<body><a href={1}><img src=\"{0}\"></body></a>", imagePath, URI); 
     mail.Display(false); 
    } 
相关问题