2017-01-30 17 views
13

Tôi đang gửi email cho các thành viên của mình và có vẻ như Gmail đang chặn hình ảnh tôi đặt trong email. Các mã này được nhúng dưới dạng một chuỗi cơ sở 64 được mã hóa trong thẻ img. Tôi đã xem xét nhiều chủ đề trực tuyến về Gmail không gửi hình ảnh nhưng không tìm thấy bất kỳ thứ gì hữu ích. Dưới đây là một số điều tôi đã thử cho đến nay. 1. bật hình ảnh bên ngoài trong Gmail (thông qua biểu tượng cài đặt) 2. giảm kích thước hình ảnh xuống dưới 8000 byte (Outlook.com sẽ không gửi hình ảnh ~ 15000 byte)Gmail chặn các hình ảnh nội tuyến nhúng nhỏ trong mẫu email

Tôi nhận được hình ảnh tốt nếu tôi gửi đến địa chỉ email outlook.com, nhưng trong Gmail, thẻ src của thẻ img trống và không có hình ảnh nào hiển thị trong email. Tôi đang sử dụng https://putsmail.com để kiểm tra/gửi email của mình, vì vậy tôi biết vấn đề không phải là vấn đề với SendGrid (dịch vụ gửi email của tôi) hoặc đơn đăng ký của tôi.

Đây là một trong các mẫu của tôi bên dưới. Tôi đang sử dụng một mẫu email từ litmuss. Tất cả mọi thứ bên dưới về cơ bản là mặc định ngoại trừ thông tin bổ sung mà tôi đã thêm như hình ảnh và một số văn bản bổ sung trong nội dung email.

Dưới đây là jsfiddle với mẫu hoàn chỉnh có dữ liệu hình ảnh có thể được sao chép ngay vào trong email và được gửi để kiểm tra! Bất kỳ trợ giúp hoặc thông tin nào về lý do Gmail không gửi hình ảnh sẽ tuyệt vời!

<!DOCTYPE html> 
 
<html> 
 
<head> 
 
    <title></title> 
 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 
    <meta name="viewport" content="width=device-width, initial-scale=1"> 
 
    <meta http-equiv="X-UA-Compatible" content="IE=edge" /> 
 
    <style type="text/css"> 
 
     /* FONTS */ 
 
     @@media screen { 
 
      @@font-face { 
 
       font-family: 'Lato'; 
 
       font-style: normal; 
 
       font-weight: 400; 
 
       src: local('Lato Regular'), local('Lato-Regular'), url(https://fonts.gstatic.com/s/lato/v11/qIIYRU-oROkIk8vfvxw6QvesZW2xOQ-xsNqO47m55DA.woff) format('woff'); 
 
      } 
 

 
      @@font-face { 
 
       font-family: 'Lato'; 
 
       font-style: normal; 
 
       font-weight: 700; 
 
       src: local('Lato Bold'), local('Lato-Bold'), url(https://fonts.gstatic.com/s/lato/v11/qdgUG4U09HnJwhYI-uK18wLUuEpTyoUstqEm5AMlJo4.woff) format('woff'); 
 
      } 
 

 
      @@font-face { 
 
       font-family: 'Lato'; 
 
       font-style: italic; 
 
       font-weight: 400; 
 
       src: local('Lato Italic'), local('Lato-Italic'), url(https://fonts.gstatic.com/s/lato/v11/RYyZNoeFgb0l7W3Vu1aSWOvvDin1pK8aKteLpeZ5c0A.woff) format('woff'); 
 
      } 
 

 
      @@font-face { 
 
       font-family: 'Lato'; 
 
       font-style: italic; 
 
       font-weight: 700; 
 
       src: local('Lato Bold Italic'), local('Lato-BoldItalic'), url(https://fonts.gstatic.com/s/lato/v11/HkF_qI1x_noxlxhrhMQYELO3LdcAZYWl9Si6vvxL-qU.woff) format('woff'); 
 
      } 
 
     } 
 

 
     /* CLIENT-SPECIFIC STYLES */ 
 
     body, table, td, a { 
 
      -webkit-text-size-adjust: 100%; 
 
      -ms-text-size-adjust: 100%; 
 
     } 
 

 
     table, td { 
 
      mso-table-lspace: 0pt; 
 
      mso-table-rspace: 0pt; 
 
     } 
 

 
     img { 
 
      -ms-interpolation-mode: bicubic; 
 
     } 
 

 
     /* RESET STYLES */ 
 
     img { 
 
      border: 0; 
 
      height: auto; 
 
      line-height: 100%; 
 
      outline: none; 
 
      text-decoration: none; 
 
     } 
 

 
     table { 
 
      border-collapse: collapse !important; 
 
     } 
 

 
     body { 
 
      height: 100% !important; 
 
      margin: 0 !important; 
 
      padding: 0 !important; 
 
      width: 100% !important; 
 
     } 
 

 
     /* iOS BLUE LINKS */ 
 
     a[x-apple-data-detectors] { 
 
      color: inherit !important; 
 
      text-decoration: none !important; 
 
      font-size: inherit !important; 
 
      font-family: inherit !important; 
 
      font-weight: inherit !important; 
 
      line-height: inherit !important; 
 
     } 
 

 
     /* MOBILE STYLES */ 
 
     @@media screen and (max-width:600px) { 
 
      h1 { 
 
       font-size: 32px !important; 
 
       line-height: 32px !important; 
 
      } 
 
     } 
 

 
     /* ANDROID CENTER FIX */ 
 
     div[style*="margin: 16px 0;"] { 
 
      margin: 0 !important; 
 
     } 
 
    </style> 
 
</head> 
 
<body style="background-color: #f4f4f4; margin: 0 !important; padding: 0 !important;"> 
 

 
    <!-- HIDDEN PREHEADER TEXT --> 
 
    <div style="display: none; font-size: 1px; color: #fefefe; line-height: 1px; font-family: 'Lato', Helvetica, Arial, sans-serif; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden;"> 
 
     We're thrilled you created a YogaBandy event! Get ready for members to register. 
 
    </div> 
 

 
    <table border="0" cellpadding="0" cellspacing="0" width="100%"> 
 
     <!-- LOGO --> 
 
     <tr> 
 
      <td bgcolor="#16749F" align="center"> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       <table align="center" border="0" cellspacing="0" cellpadding="0" width="600"> 
 
       <tr> 
 
       <td align="center" valign="top" width="600"> 
 
       <![endif]--> 
 
       <table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;"> 
 
        <tr> 
 
         <td align="center" valign="top" style="padding: 40px 10px 40px 10px;"> 
 
          <a href="https://YogaBandy.com" target="_blank"> 
 
           <img alt="Logo" src="http://litmuswww.s3.amazonaws.com/community/template-gallery/ceej/logo.png" width="40" height="40" style="display: block; width: 40px; max-width: 40px; min-width: 40px; font-family: 'Lato', Helvetica, Arial, sans-serif; color: #ffffff; font-size: 18px;" border="0"> 
 
          </a> 
 
         </td> 
 
        </tr> 
 
       </table> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       </td> 
 
       </tr> 
 
       </table> 
 
       <![endif]--> 
 
      </td> 
 
     </tr> 
 
     <!-- HERO --> 
 
     <tr> 
 
      <td bgcolor="#16749F" align="center" style="padding: 0px 10px 0px 10px;"> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       <table align="center" border="0" cellspacing="0" cellpadding="0" width="600"> 
 
       <tr> 
 
       <td align="center" valign="top" width="600"> 
 
       <![endif]--> 
 
       <table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;"> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="center" valign="top" style="padding: 40px 20px 20px 20px; border-radius: 4px 4px 0px 0px; color: #111111; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 48px; font-weight: 400; letter-spacing: 4px; line-height: 48px;"> 
 
          <h2 style="font-size: 48px; font-weight: 400; margin: 0;">Event Created</h2> 
 
         </td> 
 
        </tr> 
 
       </table> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       </td> 
 
       </tr> 
 
       </table> 
 
       <![endif]--> 
 
      </td> 
 
     </tr> 
 
     <!-- COPY BLOCK --> 
 
     <tr> 
 
      <td bgcolor="#f4f4f4" align="center" style="padding: 0px 10px 0px 10px;"> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       <table align="center" border="0" cellspacing="0" cellpadding="0" width="600"> 
 
       <tr> 
 
       <td align="center" valign="top" width="600"> 
 
       <![endif]--> 
 
       <table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;"> 
 
        <!-- COPY --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;">We're excited you have created an event. Here are some of the details below.</p> 
 
         </td> 
 
        </tr> 
 
        <!-- Host Space --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;"> 
 
           <a href="https://www.YogaBandy.com/Space/Public/@Model.SpaceId" target="_blank" class="thumbnail" style="margin-bottom: 0px;"> 
 
            <img alt="SpaceImage" title="Space Image" style="display: block" width="225" height="126" src="data:image/jpg;base64,@Raw(Model.SpaceThumbnail)" /> 
 
            <div class="caption"> 
 
             @Model.SpaceName 
 
            </div> 
 
           </a> 
 
          </p> 
 
         </td> 
 
        </tr> 
 
        <!-- Host Image --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;"> 
 
           <a href="https://www.YogaBandy.com/Profile/Public/@Model.HostId" target="_blank" class="thumbnail" style="margin-bottom: 0px;"> 
 
            <img alt="HostImage" title="Host Image" style="display: block" width="225" height="225" src="data:image/jpg;base64,@Raw(Model.HostThumbnail)" /> 
 
            <div class="caption"> 
 
             @Model.HostName 
 
            </div> 
 
           </a> 
 
          </p> 
 
         </td> 
 
        </tr> 
 
        <!-- DATE --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;">@Model.Date.ToLongDateString()</p> 
 
         </td> 
 
        </tr> 
 
        <!-- TIME --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;"> 
 
           <div>Time: @Model.Date.ToShortTimeString()</div> 
 
          </p> 
 
         </td> 
 
        </tr> 
 
        <!-- Location --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;">@Model.Location</p> 
 
         </td> 
 
        </tr> 
 
        <!-- DURATION --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;">@Model.Duration</p> 
 
         </td> 
 
        </tr> 
 
        <!-- STYLE --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 20px 30px 40px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;">@Model.Style</p> 
 
         </td> 
 
        </tr> 
 
        <!-- BULLETPROOF BUTTON --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left"> 
 
          <table width="100%" border="0" cellspacing="0" cellpadding="0"> 
 
           <tr> 
 
            <td bgcolor="#ffffff" align="center" style="padding: 20px 30px 60px 30px;"> 
 
             <table border="0" cellspacing="0" cellpadding="0"> 
 
              <tr> 
 
               <td align="center" style="border-radius: 3px;" bgcolor="#16749F"><a href="" target="_blank" style="font-size: 20px; font-family: Helvetica, Arial, sans-serif; color: #ffffff; text-decoration: none; color: #ffffff; text-decoration: none; padding: 15px 25px; border-radius: 2px; border: 1px solid #16749F; display: inline-block;">Add To Calendar</a></td> 
 
              </tr> 
 
             </table> 
 
            </td> 
 
           </tr> 
 
          </table> 
 
         </td> 
 
        </tr> 
 
        
 
        
 
        <!-- COPY --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 0px 30px 20px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;">If you have any questions, just send an email to the support address—we're always happy to help out.</p> 
 
         </td> 
 
        </tr> 
 
        <!-- COPY --> 
 
        <tr> 
 
         <td bgcolor="#ffffff" align="left" style="padding: 0px 30px 40px 30px; border-radius: 0px 0px 4px 4px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <p style="margin: 0;">Cheers,<br>The YogaBandy Team</p> 
 
         </td> 
 
        </tr> 
 
       </table> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       </td> 
 
       </tr> 
 
       </table> 
 
       <![endif]--> 
 
      </td> 
 
     </tr> 
 
     <!-- SUPPORT CALLOUT --> 
 
     <tr> 
 
      <td bgcolor="#f4f4f4" align="center" style="padding: 30px 10px 0px 10px;"> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       <table align="center" border="0" cellspacing="0" cellpadding="0" width="600"> 
 
       <tr> 
 
       <td align="center" valign="top" width="600"> 
 
       <![endif]--> 
 
       <table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;"> 
 
        <!-- HEADLINE --> 
 
        <tr> 
 
         <td bgcolor="#157b9d" align="center" style="padding: 30px 30px 30px 30px; border-radius: 4px 4px 4px 4px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 18px; font-weight: 400; line-height: 25px;"> 
 
          <h2 style="font-size: 20px; font-weight: 400; color: #111111; margin: 0;">Need more help?</h2> 
 
          <p style="margin: 0;"><a href="https://YogaBandy/Contact.com" target="_blank" style="color: #FFFFFF;">We&rsquo;re here, ready to help</a></p> 
 
         </td> 
 
        </tr> 
 
       </table> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       </td> 
 
       </tr> 
 
       </table> 
 
       <![endif]--> 
 
      </td> 
 
     </tr> 
 
     <!-- FOOTER --> 
 
     <tr> 
 
      <td bgcolor="#f4f4f4" align="center" style="padding: 0px 10px 0px 10px;"> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       <table align="center" border="0" cellspacing="0" cellpadding="0" width="600"> 
 
       <tr> 
 
       <td align="center" valign="top" width="600"> 
 
       <![endif]--> 
 
       <table border="0" cellpadding="0" cellspacing="0" width="100%" style="max-width: 600px;"> 
 
        <!-- NAVIGATION --> 
 
        <!-- PERMISSION REMINDER --> 
 
        <tr> 
 
         <td bgcolor="#f4f4f4" align="left" style="padding: 0px 30px 30px 30px; color: #666666; font-family: 'Lato', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: 400; line-height: 18px;"> 
 
          <p style="margin: 0;">You received this email because you just created a YogaBandy event. If it looks weird, <a href="https://YogaBandy.com" target="_blank" style="color: #111111; font-weight: 700;">view it in your browser</a>.</p> 
 
         </td> 
 
        </tr> 
 
        <!-- UNSUBSCRIBE --> 
 
        <!-- ADDRESS --> 
 

 
       </table> 
 
       <!--[if (gte mso 9)|(IE)]> 
 
       </td> 
 
       </tr> 
 
       </table> 
 
       <![endif]--> 
 
      </td> 
 
     </tr> 
 
    </table> 
 

 
</body> 
 
</html>

Trả lời

4

tl; dr

Gmail và một số khách hàng khác không thích base64 hình ảnh được mã hóa.

Full Story

Điều đầu tiên tôi làm là xem "Show Original" trong Gmail. Trước sự ngạc nhiên của tôi, nội dung thô vẫn có dữ liệu hình ảnh nhúng của bạn:

enter image description here

đó nói với tôi ngay lập tức gmail mà chỉ đơn giản là lựa chọn để lọc nội dung này ra. Tôi không thể tìm ra lý do. Một số dự đoán chỉ ra số length of encoded data itself. Những người khác nói về cách thức chung trong đó Gmail filters out images. Thậm chí còn có hồ sơ về kỹ thuật này functioning a number of years back.

Ngoài ra, khi xem cùng một email chính xác trong ứng dụng khách của bên thứ ba như Newton (trước đây là Cloud Magic), tôi thấy hình ảnh được hiển thị chính xác.

enter image description here

Tất cả điều đó chỉ ra một cách đơn giản, tuy nhiên buồn, thực tế là gmail không thích hình ảnh inline mã hóa. Không có trong trình duyệt và không có trong ứng dụng dành cho thiết bị di động của họ.

Trong thực tế, vào cuối cùng, tôi đã phát hiện ra một bài đăng từ 2013 by Campaign Monitor blog kết thúc với cùng một kết quả.

Không sử dụng hình ảnh được nhúng trong dòng.

12

Google từ chối hiển thị hình ảnh có url dữ liệu trong giao diện web của Gmail. Đó là một vấn đề đã biết (theo quan điểm của Google về một biện pháp an ninh) trong một thời gian dài bị chỉ trích cao.

Tin vui là bạn có tùy chọn khác ngoại trừ việc sử dụng hình ảnh bên ngoài.

Sử dụng tệp đính kèm nội tuyến có Content-ID hoạt động với Gmail.

Sau khi thêm hình ảnh dưới dạng tệp đính kèm nội dòng, bạn cần phải trỏ CID URLs thay vì Data URLs trong phần thân html.

Có rất nhiều thư viện hiện đại cho phép bạn gửi email có tệp đính kèm nội tuyến dễ dàng. Nhưng tôi đã viết một kịch bản mẫu trong VBScript với thư viện CDO, sẵn sàng để sử dụng nếu bạn có một hộp Windows 2000+ được cài đặt.

Hãy chuẩn bị môi trường thử nghiệm.

Đặt các tệp trong thư mục như trong ảnh chụp màn hình bên dưới.

enter image description here

tpl.html là file mẫu bạn đã cho. Bạn sẽ cần thực hiện một số thay đổi trong tệp này.

Thay thế cả hai thành phần img tương ứng với các phần sau. Lưu ý rằng url dữ liệu đã biến mất. image1image2 là ID nội dung được chỉ định cho từng tệp đính kèm nội tuyến trong tập lệnh. Không có gì liên quan đến tên tệp ở đây.

<img src="cid:image1" alt="SpaceImage" title="Space Image" style="display: block" width="225" height="126" /> 
<img src="cid:image2" alt="HostImage" title="Host Image" style="display: block" width="225" height="225" /> 

Embedded.vbs:

MsgBox "Wait while your email is being sent.", vbOKOnly Or vbInformation 

'************ CONFIGURATION ************* 
Const smtpUsername = "..." 
Const smtpPassword = "..." 
Const smtpHost = "smtp.sendgrid.net" 
Const smtpPort = 587 
Const senderEmail = "[email protected]" 
Const recipientEmail = "[email protected]" 
'************ CONFIGURATION ************* 

Const cdoRefTypeId = 0 

Set Fso = CreateObject("Scripting.FileSystemObject") 

Set objMail = CreateObject("CDO.Message") 
With objMail.Configuration 
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1 
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = smtpUsername 
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = smtpPassword 
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = smtpHost 
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = smtpPort 
    .Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 
    .Fields("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 20 'secs 
    .Fields.Update 
End With 

With objMail 
    .AutoGenerateTextBody = False 
    .From = senderEmail 
    .To = recipientEmail 
    .Subject = "Inline Image Test" 
    .BodyPart.ContentTransferEncoding = "quoted-printable" 
    .BodyPart.Charset = "utf-8" 

    'Adding images as inline attachments with Content IDs which is used with image sources. e.g. <img src="cid:image1" 
    .AddRelatedBodyPart Fso.GetAbsolutePathName("image1.jpg"), "image1", cdoRefTypeId 
    .AddRelatedBodyPart Fso.GetAbsolutePathName("image2.jpg"), "image2", cdoRefTypeId 

    'append html body from file 
    .HTMLBody = Fso.OpenTextFile("tpl.html").ReadAll 
    .Send 
End With 

MsgBox "Email successfully sent! Check your inbox.", vbOKOnly Or vbInformation 

Nhấp đúp chuột vào và chờ đợi để được hướng dẫn.

Xem thêm https://stackoverflow.com/search?q=is%3Aquestion+%5Bemail%5D+inline+image

Các vấn đề liên quan