전자 메일 메시지 본문 (HTML)에 여러 이미지 (차트)가 포함 된 사용자에게 전자 메일을 보내는 프로그램을 작성하고 있습니다..NET을 사용하여 전자 메일 본문에 여러 이미지를 포함하는 방법
여기에있는 샘플을 시도했을 때 ... 하나의 이미지 만 포함해야 할 때 잘 작동했습니다. http://www.systemnetmail.com/faq/4.4.aspx.
그러나 아래 코드를 사용하여 여러 이미지를 포함하려고 시도했지만 이미지가 포함되지 않고 대신 첨부 파일로 전송됩니다.
public MailMessage MailMessage(Metric metric, DateTime date)
{
MailMessage msg = new MailMessage();
msg.From = new MailAddress("[email protected]", "User1");
msg.To.Add(new MailAddress("[email protected]"));
msg.Subject = "Trend for metric: " + metric.Name;
msg.IsBodyHtml = true;
// Generate the charts for the given metric
var charts = this.GenerateCharts(metric, date);
int i = 0;
string htmlBody = "<html><body>";
List<LinkedResource> resources = new List<LinkedResource>();
foreach (var chart in charts)
{
string imageTag = string.Format("<img src=cid:chart{0} /><br>", i);
htmlBody += imageTag;
LinkedResource graph = new LinkedResource(chart.Value, "image/jpeg");
graph.ContentId = "chart" + i;
resources.Add(graph);
i++;
}
htmlBody += "</body></html>";
// Alternate view for embedded images
AlternateView avText = AlternateView.CreateAlternateViewFromString(metric.Name, null, MediaTypeNames.Text.Html);
AlternateView avImages = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
// Add all the images as linked resources
resources.ForEach(x => avImages.LinkedResources.Add(x));
// Add the views for image
msg.AlternateViews.Add(avText);
msg.AlternateViews.Add(avImages);
return msg;
}
내가 누락 된 단서가 있습니까? 은 또한 이메일과 첨부 파일로 전송되는 .htm 파일을 확인, 다음과 같이 HTML 소스 보인다 :
<html>><body><img src=cid:chart0 /><br><img src=cid:chart1 /><br><img src=cid:chart2/><br><img src=cid:chart3 /><br><img src=cid:chart4 /><br></body></html>
그래서 질문이 아닌 첨부 파일로, HTML 본문에 여러 개의 이미지를 전송하는 방법입니다.
[C#에서 본문에 포함 된 이미지가 포함 된 전자 메일 보내기] 가능한 복제본 (http://stackoverflow.com/questions/1921275/sending-an-email-with-an-image-embedded-in-the- body-from-c) –