How to embed multiple images in email body using .NET

后端 未结 7 2249
孤城傲影
孤城傲影 2020-11-29 06:26

I\'m writing a program that sends emails to users with multiple images (charts) embedded in the Email message body (HTML).

When I tried the sample located here..whic

7条回答
  •  盖世英雄少女心
    2020-11-29 06:48

    So, I think figured out what the actual problem is Its in this line

    // Alternate view for embedded images
        AlternateView avText = AlternateView.CreateAlternateViewFromString(metric.Name, null, MediaTypeNames.Text.Html);
        AlternateView avImages = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
    

    As you can see, both my views are specified as Text.Html, so the the 1st one is overriding the next one and so I only see text and images are sent as attachments

    I made the following change and it worked as expected

    AlternateView avText = AlternateView.CreateAlternateViewFromString(metric.Name, null, **MediaTypeNames.Text.Plain**);
    AlternateView avImages = AlternateView.CreateAlternateViewFromString(htmlBody, null, MediaTypeNames.Text.Html);
    

提交回复
热议问题