我想在c#mail中嵌入来自网址的图片,我尝试使用此代码,但它无法正常工作
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);
答案 0 :(得分:6)
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);
答案 1 :(得分: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);