问题
I want to embed a image from an url in c# mail, I tried using this code but it is not working
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);
回答1:
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);
回答2:
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);
来源:https://stackoverflow.com/questions/19002685/image-url-in-linked-resource