使用带有嵌入式图片的Indy 9发送电子邮件 [英] Sending email with Indy 9 with an embedded picture

查看:72
本文介绍了使用带有嵌入式图片的Indy 9发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将具有Indy 9的SMTP通过SMTP发送html电子邮件的功能添加到我的程序中。如果该程序仅包含文本(文本将以希伯来语显示,那么我需要从右到左显示它)我正在使用HTML语句),则可以正确发送电子邮件。我的问题在于将图片嵌入HTML流中。



HTML流将使用



<$ p $这样的命令p> < IMG SRC = cid:foo4atfoo1atbar.net ALT = IETF徽标>

虽然Indy 10组件TIdAttachmentFile具有ComponentID属性,但其值必须设置为 cid'引用中,我找不到在Indy 9中设置ComponentID属性的位置。



目前,用于添加图片的代码(其名称为如果是laPicture.text<> ;,则在laPicture.text中)

  ’’然后
与TIdAttachment.Create(email.MessageParts,laPicture.text)做
开始
ContentDisposition:= inline;
ContentType:=‘图片/ jpeg’;
DisplayName:= ExtractFileName(laPicture.text);
filename:= ExtractFileName(laPicture.text);
结尾;

在哪里定义ContentID?



并且,尽管这是一个愚蠢的问题,但我怎么知道我拥有的Indy版本?

解决方案

TIdAttachment 源自 TIdMessagePart ,它具有公共的 ContentID 属性。如果您安装的Indy 9版本没有该属性,则您使用的版本已过时,因此请使用 ExtraHeaders 属性添加 Content -ID 标头。



有关使用HTML电子邮件的更多信息,请查看Indy网站上的以下博客文章:



HTML消息



更新:因此,如果HTML中显示 cid:foo4atfoo1atbar.net ,您需要在代码中执行此操作以使其匹配:

  with TIdAttachment.Create(email.MessageParts,laPicture.text) 
开始
...
ContentID:='< foo4atfoo1atbar.net>';
//或如果您没有可用的ContentID属性:
// ExtraHeaders.Values [’Content-ID’]:=‘< foo4atfoo1atbar.net>’;
结尾;

请注意,在Indy 9中,您必须手动提供括号。如果省略,Indy 10会为您插入它们,例如:

  ContentID:=‘foo4atfoo1atbar.net’; 


I am trying to add to a program of mine the capability of sending html email via SMTP with Indy 9. If the program only contains text (the text will be in Hebrew so I need to display it right to left, which means that I am using HTML statements), then the email is sent correctly. My problem lays with embedding pictures into the HTML stream.

The HTML stream will use a command like

<IMG SRC="cid:foo4atfoo1atbar.net" ALT="IETF logo">

Whilst the Indy 10 component TIdAttachmentFile has a ComponentID property whose value has to be set to the value that 'cid' references, I can't find where to set the ComponentID property in Indy 9.

At the moment, the code which deals with adding the picture (whose name is in laPicture.text) looks like this

  if laPicture.text <> '' then
  with TIdAttachment.Create (email.MessageParts, laPicture.text) do
   begin
    ContentDisposition:= 'inline';
    ContentType:= 'image/jpeg';
    DisplayName:= ExtractFileName (laPicture.text);
    filename:= ExtractFileName (laPicture.text);
   end;

Where do I define the ContentID?

And, although this is a stupid question, how do I know which version of Indy I have?

解决方案

TIdAttachment derives from TIdMessagePart, which has a public ContentID property. If your installed version of Indy 9 does not have that property, then you are using an outdated version, so use the ExtraHeaders property instead to add a Content-ID header manually.

Have a look at the following blog article on Indy's website for more information about working with HTML emails:

HTML Messages

Update: so, if the HTML says cid:foo4atfoo1atbar.net then you need to do this in your code to match it:

with TIdAttachment.Create (email.MessageParts, laPicture.text) do
begin
  ...
  ContentID := '<foo4atfoo1atbar.net>';
  // or this, if you do not have the ContentID property available:
  // ExtraHeaders.Values['Content-ID'] := '<foo4atfoo1atbar.net>';
end;

Note that in Indy 9, you have to provide the brackets manually. Indy 10 inserts them for you if they are omitted, eg:

ContentID := 'foo4atfoo1atbar.net';

这篇关于使用带有嵌入式图片的Indy 9发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆