unit Unit1;interfaceuses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Buttons, OleCtrls, SHDocVw, Provider, IdMessage, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient, IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, HTTPApp, HTTPProd, DSProd,IdAttachmentFile,idtext;type TForm1 = class(TForm) IdSMTP1: TIdSMTP; IdMessage1: TIdMessage; OpenDialog1: TOpenDialog; Memo1: TMemo; WebBrowser1: TWebBrowser; ListBox1: TListBox; edtRecipients: TEdit; ediSubject: TEdit; btnSend: TBitBtn; btnImportItml: TBitBtn; DataSetPageProducer1: TDataSetPageProducer; procedure btnImportItmlClick(Sender: TObject); procedure btnSendClick(Sender: TObject); private { Private declarations } public { Public declarations } end;var Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btnImportItmlClick(Sender: TObject); var s,s1,s2:string; attfile:Tstringlist; i,j:integer;begin if opendialog1.Execute then { if FileExists(temp-filename) then deletefile(temp-filename); temp-filename:=''; now-dir:=extractfilepath(opendialog1.FileName); } memo1.Lines.LoadFromFile(opendialog1.FileName); attfile:=TStringlist.Create; s1:=memo1.Text; s2:='.BMP"'; while(pos(s2,uppercase(s1)))>0 do begin i:=pos(s2,uppercase(s1)); j:=i; while(s1[i]<>'"')and(i>0)do i:=i-1; if i>0 then begin s:=copy(s1,i+1,j+3-i); if(attfile.IndexOf(s)<0)and(pos('HTTP://',uppercase(s))=0)then attfile.Add(s); end; s1:=copy(s1,j+5,length(s1)-j-4); end; listbox1.Items.AddStrings(attfile); DataSetPageProducer1.HTMLFile:=''; DataSetPageProducer1.HTMLDoc.Text:=memo1.Text; attfile.Free;end;procedure TForm1.btnSendClick(Sender: TObject); var i,j:integer; id1,id2,id3,s:string; idc:integer; memo_s:string; begin with idsmtp1 do begin host:='smtp.163.com'; Username:='zdajio'; Password:='44580498'; try connect(); except exit; end; end; with idmessage1 do begin messageparts.Clear; for i := 0 to listbox1.Count - 1 do begin with TIdAttachmentFile.Create(idmessage1.MessageParts,ListBox1.Items[i]) do s:=ListBox1.Items[i]; j:=pos(s,memo1.Text); if i>0 then begin id3:=''; if pos('.JPG',uppercase(s))>0 then begin ContentType:='image/jpeg'; inc(idc); id3:='content-id:<'+id2+formatfloat('00000',idc)+id1+'>'; end; if pos('.GIF',uppercase(s))>0 then begin ContentType:='image/gif'; inc(idc); id3:='content-id:<'+id2+formatfloat('00000',idc)+id1+'>'; end; if pos('.BMP',uppercase(s))>0 then begin ContentType:='image/bmp'; inc(idc); id3:='content-id:<'+id2+formatfloat('00000',idc)+id1+'>'; end; ContentTransferEncoding:='base64'; if not(id3='') then begin ExtraHeaders.Add(id3); while j>0 do begin memo1.Text:=copy(memo1.Text,1,j-1)+'cid:'+id2+formatfloat('00000',idc) +id1 +copy(memo1.Text,j+length(ListBox1.Items[i]),length(memo1.Text)-j+1-length(ListBox1.Items[i])); j:=pos(s,memo1.Text); end; end; end; end; end; Tidtext.Create(idmessage1.MessageParts); with TIdText.Create(IdMessage1.MessageParts,memo1.Lines) do begin contentType:='text/html'; end; IdMessage1.Recipients.EMailAddresses:=edtRecipients.Text; IdMessage1.Subject:=ediSubject.Text; idmessage1.charset:='gb2312'; IdMessage1.Body:=memo1.Lines; idmessage1.From.Text:='[email protected]';with idsmtp1 do begin Send(IdMessage1); end; end; end.我还是附上我的代码把 帮我看看 那里错了
内置图片的邮件格式://主PART
Content-Type: multipart/alternative;boundary="----=_NextPart_002_0085_01CC9109.ABE77E30"
//正文PART
Content-Type: multipart/alternative;boundary="----=_NextPart_002_0085_01CC9109.ABE77E30"
//HTML格式的正文PART
Content-Type: text/html;charset=UTF-8
Content-Transfer-Encoding: quoted-printable<BODY id=ridBody background=cid:364DAA89F0994B4D9B409AC2D26ADE42@wendypc '#$D#$A'bgColor=#ffffff>
//CID:364DAA89F0994B4D9B409AC2D26ADE42@wendypc表示它引用的是CONTENT-ID为
//364DAA89F0994B4D9B409AC2D26ADE42@wendypc的资源//文本格式的正文PART
Content-Type: text/plain;charset=UTF-8
Content-Transfer-Encoding: quoted-printable//内置附件--图片,它的Content-ID为364DAA89F0994B4D9B409AC2D26ADE42
Content-Type: image/gif;name="Ivy.gif"
Content-Transfer-Encoding: base64
Content-ID: <364DAA89F0994B4D9B409AC2D26ADE42@wendypc>
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Buttons, OleCtrls, SHDocVw, Provider, IdMessage,
IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
IdExplicitTLSClientServerBase, IdMessageClient, IdSMTPBase, IdSMTP, HTTPApp,
HTTPProd, DSProd,IdAttachmentFile,idtext;type
TForm1 = class(TForm)
IdSMTP1: TIdSMTP;
IdMessage1: TIdMessage;
OpenDialog1: TOpenDialog;
Memo1: TMemo;
WebBrowser1: TWebBrowser;
ListBox1: TListBox;
edtRecipients: TEdit;
ediSubject: TEdit;
btnSend: TBitBtn;
btnImportItml: TBitBtn;
DataSetPageProducer1: TDataSetPageProducer;
procedure btnImportItmlClick(Sender: TObject);
procedure btnSendClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;var
Form1: TForm1;implementation{$R *.dfm}procedure TForm1.btnImportItmlClick(Sender: TObject);
var
s,s1,s2:string;
attfile:Tstringlist;
i,j:integer;begin
if opendialog1.Execute then
{ if FileExists(temp-filename) then
deletefile(temp-filename);
temp-filename:='';
now-dir:=extractfilepath(opendialog1.FileName);
}
memo1.Lines.LoadFromFile(opendialog1.FileName);
attfile:=TStringlist.Create;
s1:=memo1.Text;
s2:='.BMP"';
while(pos(s2,uppercase(s1)))>0 do
begin
i:=pos(s2,uppercase(s1));
j:=i;
while(s1[i]<>'"')and(i>0)do
i:=i-1;
if i>0 then
begin
s:=copy(s1,i+1,j+3-i);
if(attfile.IndexOf(s)<0)and(pos('HTTP://',uppercase(s))=0)then
attfile.Add(s); end;
s1:=copy(s1,j+5,length(s1)-j-4);
end;
listbox1.Items.AddStrings(attfile);
DataSetPageProducer1.HTMLFile:='';
DataSetPageProducer1.HTMLDoc.Text:=memo1.Text;
attfile.Free;end;procedure TForm1.btnSendClick(Sender: TObject);
var
i,j:integer;
id1,id2,id3,s:string;
idc:integer;
memo_s:string;
begin
with idsmtp1 do
begin
host:='smtp.163.com';
Username:='zdajio';
Password:='44580498';
try
connect();
except
exit; end;
end;
with idmessage1 do
begin
messageparts.Clear;
for i := 0 to listbox1.Count - 1 do
begin
with TIdAttachmentFile.Create(idmessage1.MessageParts,ListBox1.Items[i]) do
s:=ListBox1.Items[i];
j:=pos(s,memo1.Text);
if i>0 then
begin
id3:='';
if pos('.JPG',uppercase(s))>0 then
begin
ContentType:='image/jpeg';
inc(idc);
id3:='content-id:<'+id2+formatfloat('00000',idc)+id1+'>';
end;
if pos('.GIF',uppercase(s))>0 then
begin
ContentType:='image/gif';
inc(idc);
id3:='content-id:<'+id2+formatfloat('00000',idc)+id1+'>';
end;
if pos('.BMP',uppercase(s))>0 then
begin
ContentType:='image/bmp';
inc(idc);
id3:='content-id:<'+id2+formatfloat('00000',idc)+id1+'>';
end;
ContentTransferEncoding:='base64';
if not(id3='') then
begin
ExtraHeaders.Add(id3);
while j>0 do
begin
memo1.Text:=copy(memo1.Text,1,j-1)+'cid:'+id2+formatfloat('00000',idc)
+id1
+copy(memo1.Text,j+length(ListBox1.Items[i]),length(memo1.Text)-j+1-length(ListBox1.Items[i]));
j:=pos(s,memo1.Text);
end;
end;
end;
end;
end;
Tidtext.Create(idmessage1.MessageParts);
with TIdText.Create(IdMessage1.MessageParts,memo1.Lines) do
begin
contentType:='text/html';
end;
IdMessage1.Recipients.EMailAddresses:=edtRecipients.Text;
IdMessage1.Subject:=ediSubject.Text;
idmessage1.charset:='gb2312';
IdMessage1.Body:=memo1.Lines;
idmessage1.From.Text:='[email protected]';with idsmtp1 do
begin
Send(IdMessage1);
end;
end;
end.我还是附上我的代码把 帮我看看 那里错了