0
画像をメール本文に入れてメールを送信しようとしていますが、受信したメールに画像が表示されていません。メールの本文に画像を添付するコードがあります問題を解決するのを手伝ってください。ランタイムメール本文に画像を埋め込む方法
string Body = mainContent.ToString();
AlternateView htmlView = AlternateView.CreateAlternateViewFromString(Body.ToString(), null, "text/html");
HtmlDocument document = new HtmlDocument();
document.LoadHtml(Body);
document.DocumentNode.Descendants("img")
.Where(e =>
{
string src = e.GetAttributeValue("src", null) ?? "";
return !string.IsNullOrEmpty(src) && !src.StartsWith("data:image");
})
.ToList()
.ForEach(x =>
{
string currentSrcValue = x.GetAttributeValue("src", null);
string contentId = Guid.NewGuid().ToString();
LinkedResource inline = new LinkedResource(System.Web.Hosting.HostingEnvironment.MapPath("~"+currentSrcValue));
inline.ContentId = contentId;
inline.TransferEncoding = TransferEncoding.Base64;
x.SetAttributeValue("src", "cid:" + inline.ContentId);
htmlView.LinkedResources.Add(inline);
});
string result = document.DocumentNode.OuterHtml;
mail.IsBodyHtml = true;
htmlView = AlternateView.CreateAlternateViewFromString(result.ToString(), null, "text/html");
mail.AlternateViews.Add(htmlView);
電子メールに画像を埋め込む簡単な方法については、[this StackOverflow Link](http://stackoverflow.com/a/30126266/2803565)を参照してください。 –