发送提醒电子邮件的每日程序未显示嵌入图像

问题描述 投票:0回答:0

我有一个程序每天都会向注册参加活动的人发送提醒电子邮件。除了图像一直显示为损坏之外,一切正常。我正在使用 C# .NET Core。下面是html。

文件结构为:

  • 服务
    • 电子邮件
      • 提醒电子邮件.cs
  • wwwroot
    • 图片
      • 电子邮件徽标.png
string body = @"
<html>
    <body>
        <img src='wwwroot/img/email-logo.png' width=300 height=100 />
        <p style='color: black;'>Just a reminder, the program you are scheduled to attend is starting soon, the details for your group are below. We look forward to working with you.</p>
            
        <p style='color: black;'><strong>FULL HOCKEY EQUIPMENT</strong>, including your hockey stick, is required. Please arrive approximately 30 minutes prior to the program on the first day so we can get you checked in, and you have time to get dressed. Please bring a water bottle with you and set it on the bench during the session.</p>
            
        <p style='color: black;'>If you are interested in our <strong>testing system</strong> or <strong>video analysis</strong>, please see the instructor at your program.<br />    
        <a href='https://prostrideskating.com/ProgramEvents/Testing'>Learn More About Testing System</a><br />
        <a href='https://prostrideskating.com/VideoAnalysis'>Learn More About Video Analysis</a></p>

            
        <p><mark><strong>Program</strong><br />
        Set Name: {programSetName}<br />
        Event Start: {formattedStartDate}<br />
        Event End: {formattedEndDate}<br />
        Details: {details}</mark></p>
         
        <p><mark><strong>Location</strong><br />
        {locationName}<br />
        {address}<br />
        {city}, {state} {postalCode}<br />
        {country}</mark></p>
            
        <p style='color: black;'>If for any reason you cannot attend, please refer to our <a href='https://www.prostrideskating.com/Terms'>cancellation policy</a> and contact us prior to the start of the program.</p

        <hr />

        <p style='color: black;'>Pro Stride Elite Skating<br />
        <a href='www.prostrideskating.com'>www.prostrideskating.com</a><br />
        Office: 508-406-7552<br />
        Email: <a href='mailto:[email protected]'>[email protected]</a></p>
    </body>
</html>";"

这是发送电子邮件的代码:

var mail = new MimeMessage();
                mail.From.Add(new MailboxAddress("name", username));
                mail.To.Add(new MailboxAddress(email, email));
                //mail.Cc.Add(new MailboxAddress("name", "[email protected]"));
                mail.Subject = "Subject"
                mail.Body = new TextPart("html")
                {
                    Text = body
                };

我测试了路径以确保它是正确的并且看起来是正确的。我尝试将其转换为 Base64 字符串,例如:

string imagePath = "wwwroot/img/email-logo.png";

// Read the content of the image file
byte[] imageBytes = System.IO.File.ReadAllBytes(imagePath);

// Convert the byte array to a base64 string
string base64String = Convert.ToBase64String(imageBytes);

//html code
<html>
  <body>
    <img src='data:image/png;base64,base64String' width=100 height=30 />
... rest of code

并且电子邮件显示的是 base64 字符串而不是图像,这也不正确。

c# html asp.net email html-email
© www.soinside.com 2019 - 2024. All rights reserved.