2013-04-29 118 views
-2

我試圖通過電子郵件直接發送HTML模板沒有頁面的複製粘貼,我的意思是隻是把HTML代碼,併發送它作爲該HTML頁面不是原始文本,主要原因是通過Delphi發送這個HTML模板。DELPHI中的電子郵件中的HTML

的問題是我們從HTML獲取只有文字,我的意思是隻有這部分:

<p>Hola chicos!</p> 
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 

,什麼我不能得到它顯示的這些行:

<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" background="http://www.feelmalagahostel.com/emails/content.jpg"> 
<table width="800" border="0" cellspacing="0" cellpadding="0" background="http://www.feelmalagahostel.com/emails/header_feel_summer.jpg" style="background-position:top; background-repeat:no-repeat;"> 
<table width="800" border="0" align="center" cellpadding="0" cellspacing="0" background="http://www.feelmalagahostel.com/emails/footer.jpg" style="background-position:bottom; background-repeat:no-repeat;"> 

它只是省略它們,顯示標記圖像而不顯示背景圖像。

這樣的問題,我該如何做到在電子郵件中顯示?並需要背景圖片。

的HTML代碼:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<body marginheight="0" marginwidth="0"> 
    <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" background="http://www.feelmalagahostel.com/emails/content.jpg"> 
     <tr> 
      <td valign="top"> 
       <table width="800" border="0" cellspacing="0" cellpadding="0" background="http://www.feelmalagahostel.com/emails/header_feel_summer.jpg" style="background-position:top; background-repeat:no-repeat;"> 
        <tr> 
         <td align="center" valign="top"> 
          <!--header--> 
          <table width="730" border="0" align="center" cellpadding="0" cellspacing="0"> 
           <tr> 
            <td height="230">&nbsp;</td> 
           </tr> 
           <tr> 
            <td height="100" align="right" valign="top"> 
             <table border="0" cellspacing="0" cellpadding="0"> 
              <tr></tr> 
             </table> 
            </td> 
           </tr> 
           <tr> 
            <td height="10">&nbsp;</td> 
           </tr> 
           <tr> 
            <td height="61" align="right"> 
             <img src="https://www.auto21.ca/userImages/images/test%20drive%20logo%20FINAL.jpg" width="347" height="61" /> 
            </td> 
           </tr> 
          </table> 
          <!--end header--> 
          <br/> 
          <br/> 
          <!--content--> 
          <table width="600" border="0" cellspacing="0" cellpadding="0" align="center"> 
           <tr> 
            <td valign="top"> <font face="Arial, Helvetica, sans-serif" size="2"> 
    <p>Hola chicos!</p> 
    <p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p> 
    <p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci </p> 
    <p>velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p> 
    </font> 
            </td> 
           </tr> 
          </table> 
          <!--end content--> 
         </td> 
        </tr> 
       </table> 
      </td> 
     </tr> 
    </table> 
    <table width="800" border="0" align="center" cellpadding="0" cellspacing="0" background="http://www.feelmalagahostel.com/emails/footer.jpg" style="background-position:bottom; background-repeat:no-repeat;"> 
     <tr> 
      <td valign="top"> 
       <!--footer--> 
       <table width="600" border="0" cellspacing="0" cellpadding="0" align="center"> 
        <tr> 
         <td height="300" valign="top"></td> 
        </tr> 
        <tr height="250"> 
         <td></td> 
        </tr> 
       </table> 
       <!--end footer--> 
      </td> 
     </tr> 
    </table> 
</body> 

</html> 
+2

什麼問題呢?只是['do it'](http://www.indyproject.org/Sockets/Blogs/RLebeau/2005_08_17_A.EN.aspx);-) – TLama 2013-04-29 22:49:55

+2

我在這裏沒有看到任何問題,只是告訴我們你想要做一點事。 – 2013-04-29 22:55:41

+0

我認爲他想發送HTML * AS IS *,即作爲文本,而不是HTML。在這種情況下,使用由JachGate提供的代碼,您可以將字符串添加到電子郵件的* text *屬性中,而不是其HTML屬性。 – 2013-04-30 03:10:41

回答

5

有很多方法來發送電子郵件與德爾福。

我最喜歡的是通過SMTP類TIdSMTP,它是INDY項目的一部分,它靈活而強大。

要發送HTML內容的郵件使用輔助類TIdMessageBuilderHtml,這在我看來不僅使事情更容易,而且還留下了更優雅和易於理解的代碼。

相關部分發送這種郵件是:

var 
    Builder: TIdMessageBuilderHtml; 
    Msg: TIdMessage; 
    SMTP: TIdSMTP; 
begin 
    Builder := TIdMessageBuilderHtml.Create; 
    try 
    Builder.Html.Add('<HTML><HEAD><TITLE>An Image for you</TITLE></HEAD><BODY>'); 
    Builder.Html.Add('<p><strong>An image for you</strong></p>'); 
    Builder.Html.Add('<div>'); 
    Builder.Html.Add(' <img border="0" src="cid:theimage" >'); 
    Builder.Html.Add('</div>'); 
    Builder.PlainText.Add('This mail have an image for you. ' 
     + 'Use a HTML viewer to see it'); 
    Builder.HtmlFiles.Add(ImageFileName, 'theimage'); 
    Msg := Builder.NewMessage(); 
    try 
     Msg.Recipients.EMailAddresses := eRecipients.Text; 
     Msg.From.Name := eFromName.Text; 
     Msg.From.Address := eFromEmail.Text; 
     Msg.Subject := 'A image for you'; 
     SMTP := TIdSMTP.Create; 
     try 
     SMTP.Host := eSMTPHost.Text; 
     SMTP.Username := eSMTPUser.Text; 
     SMTP.Password := eSMTPPass.Text; 
     SMTP.Connect; 
     try 
      SMTP.Send(Msg); 
     finally 
      SMTP.Disconnect; 
     end; 
     SMTP.Send(Msg); 
     finally 
     SMTP.Free; 
     end; 
    finally 
     Msg.Free; 
    end; 
    finally 
    Builder.Free; 
    end; 
end; 
+1

這是關於這件事的第一個簡單例子。我嘗試過的所有其他例子和許多麻煩,這個只是工作! – 2013-11-22 17:04:52

+0

對不起,我發現你在西班牙的堆棧溢出,51區的提案...你可以借用這個:http://stackoverflow.com/posts/28330370/revisions – apaul 2015-02-04 21:36:27

+1

@ apaul34208,沒問題,我已經重新編輯了問題,並向OP發送了一條消息。我希望它有幫助。 – jachguate 2015-02-05 17:44:45