代码之家  ›  专栏  ›  技术社区  ›  Antoine Pelletier

使用此技术不会在电子邮件中发送图像

  •  0
  • Antoine Pelletier  · 技术社区  · 7 年前

    我想让我的电子邮件“参数化”,这样更容易使用格式,做一些看起来专业的事情。

    我有这个文件夹:

    enter image description here

    这是消息的内容。htm:

    <html>
    <head></head>
    <body style='color:grey; font-size:15px;'>
        <font face='Helvetica, Arial, sans-serif'>
    
        <div style='position:absolute; height:100px; width:600px; padding:30px;'>
            <img src='logo.png' />
        </div>
    
        <br />
        <br />
    
        <div style='background-color: #ece8d4; width:600px; height:200px; padding:30px; margin-top:30px;'>
    
            <p>Please click the link below to login and get started.</p>
            <p>
                Username: {0}<br>
                Password: {1}<br>
            </p>
            <br />
            <p>Now get lost... cause it's just a test</p>
        </div>
        </font>
    </body>
    </html>
    

    然后在我的控制器中,使用以下c#发送它:

     string body;
     using (var sr = new StreamReader(Server.MapPath("\\Email\\Message.htm") ))
     {
         body = sr.ReadToEnd();
     }
    
    
     string username = "anto";
     string password = "RandomNumber";
    
     string messageBody = string.Format(body, username, password);
    
     EnvoieCourriel("pelletier_antoine@hotmail.com", messageBody, restOfTheParams);
    

    Emial发送正确。问题是什么? <img src='logo.png' /> 永远不会出现。我试了很多奇怪的代码。尚未接近成功。。。

    编辑:

    我想在电子邮件中发送图像,作为内联内容。

    1 回复  |  直到 7 年前
        1
  •  1
  •   scoopzilla    7 年前

    更改 HTML 要在 img 标签:

          <html>
     <head></head>
     <body style='color:grey; font-size:15px;'>
         <font face='Helvetica, Arial, sans-serif'>
    
         <div style='position:absolute; height:100px; width:600px; padding:30px;'>
             <img src='http://somepath.com/images/logo.png' />
         </div>
    
         <br />
         <br />
    
         <div style='background-color: #ece8d4; width:600px; height:200px; padding:30px; margin-top:30px;'>
    
             <p>Please click the link below to login and get started.</p>
             <p>
                 Username: {0}<br>
                 Password: {1}<br>
             </p>
             <br />
             <p>Now get lost... cause it's just a test</p>
         </div>
         </font>
     </body>
     </html>
    

    否则接收器将永远看不到该图像。