2013-04-29 47 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