http://www.experts-exchange.com/Programming/Programming_Languages/Delphi/Q_21014266.html
解决方案 »
- 寻在最好的delphi教程,书籍……
- 用流保存图片至access
- TDataLink的问题
- 控件的事件问题,急.100分.
- 怎样给用Rave设计好的RvProject1\report1\page1\中的Text Component的text属性赋值?在线等待...立即结贴!
- 请各位大侠指点一下,关于com、com+方面的知识,有好文章推荐一下也可以,最好写个把例子,多谢多谢!
- 我用WM_COPYDATA在进程之间发送消息的时候 ,出现错误!!!!!!!!
- class * not found
- 没人会吗? 急用……关于access的问题
- 制作的安装程序为什么不能在别的机了上运行?
- BMP转成JPG后...的问题.
- listview好象只有第一列才能被选种啊,怎样让后面的列被选种呢?
顺便把上面的答案也贴出来。I copied&pasted this code from an existing unit I have, and it should do exactly what you want. The trick however isn't just adding the image(s) as attachment but also telling OE or Outlook where to find them. To do this, use the "cid:imagename.jpg" tag in your HTML code for the images. Also, use the ExtraHeader property to set 'Content-ID' to the name of the image as it appears in your cid: tag. Thus, if you use:
<img src="cid:PrettyPic">
then you add this header:
Attachment.ExtraHeaders.Values['Content-ID'] := '<PrettyPic>';Now, the image MUST still be added as an attachment since pure HTML cannot handle inline images. But if you use this technique then whomever reads this email will see a background image and a second image as part of the email, exactly like you wanted it to appear. (If their browser can display HTML emails. Otherwise they see plain text.) The _attached_ will be embedded in your email this way.Here's the (stripped) code example. I hope it still works. :Dprocedure TFormMain.SendMail(Recipient, Address: string);
const
sStars = 'BackgroundStars.jpg';
var
AdressItem: TIdEMailAddressItem;
AFile: string;
AMessage: TIdMessage;
ASMTP: TIdSMTP;
AStream: TMemoryStream;
Attachment: TIdAttachment;
IdBody: TIdText;
IdHTML: TIdText;
idStars: TIdAttachment;
resStars: TStream;
TempFile: TStream;
begin
Screen.Cursor := crHourGlass;
AFile := FileListBox.FileName;
if FileExists(AFile) then begin
AMessage := TIdMessage.Create(nil);
AMessage.NoDecode := False;
AMessage.NoEncode := False;
AMessage.ContentType := 'multipart/mixed';
AMessage.Encoding := meMIME;
AMessage.MsgId := 'PrettyPic';
AMessage.References := ChangeFileExt(ExtractFileName(AFile), '');
// Set recipients.
AdressItem := AMessage.Recipients.Add;
AdressItem.Name := Recipient;
AdressItem.Address := Address;
// Set subject.
AMessage.Subject := 'Hello.';
// Set sender.
AMessage.Sender.Name := 'Workshop Alex';
AMessage.Sender.Address := '[email protected]';
// Set from.
AMessage.From.Name := AMessage.Sender.Name;
AMessage.From.Address := AMessage.Sender.Address;
// Create plain body.
IdBody := TIdText.Create(AMessage.MessageParts);
IdBody.ContentType := 'text/plain';
IdBody.Body.Add('Hello, friends.');
IdBody.Body.Add('');
// Add more to the plain-text bodypart.
// Create HTML body.
IdHTML := TIdText.Create(AMessage.MessageParts);
IdHTML.ContentType := 'text/html; charset=US-ASCII';
IdHTML.ContentTransfer := '7bit';
IdHTML.Body.Add('<html>');
IdHTML.Body.Add(' <head>');
IdHTML.Body.Add(' <title>Hello</title>');
IdHTML.Body.Add(' </head>');
IdHTML.Body.Add(' <body title="' + AMessage.References + '" background="cid:BackgroundStars">');
IdHTML.Body.Add(' Hello, friends.<br>');
IdHTML.Body.Add(' <br>');
IdHTML.Body.Add(' <img src="cid:PrettyPic" alt="' + ExtractFileName(AFile) + '" name="' + ExtractFileName(AFile) + '" title="Just an image included.">');
IdHTML.Body.Add(' </body>');
IdHTML.Body.Add('</html>');
// Add the attachment. Don't forget the extra headers!
Attachment := TIdAttachment.Create(AMessage.MessageParts, AFile);
Attachment.ExtraHeaders.Values['Content-ID'] := '<PrettyPic>';
Attachment.ContentType := 'image/jpeg';
idStars := TIdAttachment.Create(AMessage.MessageParts, ExtractFilePath(ParamStr(0)) + sStars);
idStars.ExtraHeaders.Values['Content-ID'] := '<BackgroundStars>';
idStars.ContentType := 'image/jpeg';
// Now send the thing...
ASMTP := TIdSMTP.Create(nil);
ASMTP.Host := 'mail.whatever.org';
ASMTP.Port := 25;
ASMTP.AuthenticationType := atNone;
ASMTP.Connect;
try
ASMTP.Send(AMessage);
except
on E: Exception do ShowMessageFmt('Error: %s', [E.Message]);
end;
ASMTP.Disconnect;
AMessage.Free;
ASMTP.Free;
end;
Screen.Cursor := crDefault;
end;
Comment from CesarHdez
Date: 06/07/2004 04:23PM PDT
Author Comment
Thank you very much, the code you posted works great!!!Thanks,Cesar