4

我想在 c# 邮件中嵌入来自 url 的图像,我尝试使用此代码,但它不起作用

 LinkedResource logoHeader = null;
AlternateView av1 = AlternateView.CreateAlternateViewFromString(strBody, null,   MediaTypeNames.Text.Html);
logoHeader= new LinkedResource("some xyz.com");  
logoHeader.ContentId = "logoimage";
av1.LinkedResources.Add(logo);
4

2 回答 2

9
string image = "example.com/image.jpg";
var webClient = new WebClient();
byte[] imageBytes = webClient.DownloadData(image);
MemoryStream ms = new MemoryStream(imageBytes);
LinkedResource resource = new LinkedResource(ms, MediaTypeNames.Image.Jpeg);
于 2015-08-21T08:42:05.893 回答
0
AlternateView av = AlternateView.CreateAlternateViewFromString(str,null,MediaTypeNames.Text.Html);
LinkedResource lr = new LinkedResource("E:\\Photos\\hello.jpg",MediaTypeNames.Image.Jpeg);
lr.ContentId = "image1";
av.LinkedResources.Add(lr);
message.AlternateViews.Add(av);
于 2013-09-25T10:47:52.720 回答