-2

我试图通过电子邮件直接发送 HTML 模板,而无需复制粘贴页面,我的意思是只放置 HTML 代码并将其作为 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>
4

1 回答 1

5

使用 Delphi 发送电子邮件的方法有很多种。

我最喜欢的是通过 SMTP 类来实现,它是INDY 项目TIdSMTP的一部分,它既灵活又强大。

要发送包含 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;
于 2013-04-29T22:54:46.973 回答