delphi6里如有没有直接能用控件发email的
1个回答
展开全部
NMPop3控件在delphi6中的fastnet面板上,示例代码如下笑激
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Psock, NMpop3, ExtCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
NMPOP31: TNMPOP3;
lbl1: TLabel;
pnl1: TPanel;
Memo1: TMemo;
pnl2: TPanel;
procedure downfiles(files, path: string);
procedure unzip(src, dec: string);
function ctstodatetime(date: string): TDateTime;
function loadfile(id: integer): string;
procedure NMPOP31AuthenticationFailed(var Handled: Boolean);
procedure NMPOP31Connect(Sender: TObject);
procedure NMPOP31ConnectionFailed(Sender: TObject);
procedure NMPOP31DecodeEnd(Sender: TObject);
procedure NMPOP31DecodeStart(var FileName: string);
procedure NMPOP31Disconnect(Sender: TObject);
procedure NMPOP31InvalidHost(var Handled: Boolean);
procedure NMPOP31RetrieveStart(Sender: TObject);
procedure NMPOP31RetrieveEnd(Sender: TObject);
procedure NMPOP31Success(Sender: TObject);
procedure NMPOP31PacketRecvd(Sender: TObject);
procedure showstate(s:string);
private
function StreamDecompression(mInputStream,
mOutputStream: TStream): Integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ZLib, Unit2;
{$R *.dfm}
const
cBufferSize = $4096;
{ TForm1 }
function TForm1.ctstodatetime(date: string): TDateTime;
var
yy, mm, dd, time: string;
begin
Result := Now;
//Fri, 12 Mar 2010 22:56:45 +0800 (CST)
mm := Copy(date, 9, 3);
mm := StringReplace(mm, 'Jan', '碰猜袜01', [rfReplaceAll]);
mm := StringReplace(mm, 'Feb', '02', [rfReplaceAll]);
mm := StringReplace(mm, 'Mar', '03', [rfReplaceAll]);
mm := StringReplace(mm, 'Apr', '04', [rfReplaceAll]);
mm := StringReplace(mm, 'May', '05', [rfReplaceAll]);
mm := StringReplace(mm, 'Jun', '06', [rfReplaceAll]);
mm := StringReplace(mm, 'Jul', '07', [rfReplaceAll]);
mm := StringReplace(mm, 'Aug'兆纤, '08', [rfReplaceAll]);
mm := StringReplace(mm, 'Sep', '09', [rfReplaceAll]);
mm := StringReplace(mm, 'Oct', '10', [rfReplaceAll]);
mm := StringReplace(mm, 'Nov', '11', [rfReplaceAll]);
mm := StringReplace(mm, 'Dec', '12', [rfReplaceAll]);
yy := Copy(date, 13, 4);
dd := Copy(date, 6, 2);
time := Copy(date, 18, 8);
try
result := StrToDateTime(yy + '-' + mm + '-' + dd + ' ' + time);
except
end;
end;
procedure TForm1.downfiles(files, path: string);
var
i, j: Integer;
enddate: TDateTime;
begin
// enddate := Now - 20000;
// j := -1;
NMPOP31.AttachFilePath := '.';
NMPOP31.DeleteOnRead := FALSE;
NMPOP31.ReportLevel := Status_Basic;
NMPOP31.TimeOut := 20000;
NMPOP31.Host := 'pop.163.com';
NMPOP31.Port := 110;
NMPOP31.UserID :='邮箱用户名';
NMPOP31.Password :='邮箱密码';
NMPOP31.Connect;
if NMPOP31.MailCount = 0 then
begin
ShowMessage('服务器中没有最新数据。');
NMPOP31.Disconnect;
showstate('');
exit;
end;
Memo1.Lines.Clear;
for i := 1 to NMPOP31.MailCount do
begin
NMPOP31.GetSummary(i);//收摘要信息
Memo1.Lines.Add('subject: '+(NMPOP31.Summary.Subject));// Base64Decode
Memo1.Lines.Add('from: '+NMPOP31.Summary.From);
Memo1.Lines.Add('MessageId: '+NMPOP31.Summary.MessageId);
Memo1.Lines.Add('Header: '+NMPOP31.Summary.Header.Text);
Memo1.Lines.Add('CommaText: '+NMPOP31.Summary.Header.CommaText);
Memo1.Lines.Add('DelimitedText: '+NMPOP31.Summary.Header.DelimitedText);
Memo1.Lines.Add('NameValueSeparator: '+NMPOP31.Summary.Header.NameValueSeparator);
Memo1.Lines.Add('GetNamePath: '+NMPOP31.Summary.GetNamePath);
Memo1.Lines.Add('---------');
// if Trim(NMPOP31.Summary.Subject) = files then
// begin
// if ctstodatetime(NMPOP31.Summary.Header.Values['date']) > enddate then
// begin
// if j > 0 then
// NMPOP31.DeleteMailMessage(j);
// enddate := ctstodatetime(NMPOP31.Summary.Header.Values['date']);
// j := i;
// end
// else
// NMPOP31.DeleteMailMessage(i);
// end;
end;
// if j = -1 then
// begin
// ShowMessage('服务器中没有最新数据。');
// NMPOP31.Disconnect;
// showstate('');
// exit
// end;
// NMPOP31.GetMailMessage(j);//收完整信息
// unzip(NMPOP31.MailMessage.Attachments[0], path);
// DeleteFile('.\' + NMPOP31.MailMessage.Attachments[0]);
// DeleteFile('.\temp1.mme');
// NMPOP31.DeleteMailMessage(j);
NMPOP31.Disconnect;
// showmessage('成功下载数据。');
showstate('');
end;
procedure TForm1.unzip(src, dec: string);
var
vInputStream: TFileStream;
vOutputStream: TFileStream;
begin
vInputStream := TFileStream.Create(src, fmOpenRead);
vOutputStream := TFileStream.Create(dec, fmCreate);
try
StreamDecompression(vInputStream, vOutputStream);
finally
vInputStream.Free;
vOutputStream.Free;
end;
end;
function TForm1.StreamDecompression(mInputStream: TStream; mOutputStream:
TStream):
Integer;
var
vBuffer: array[0..cBufferSize] of Char;
I: Integer;
begin
Result := -1;
if not (Assigned(mInputStream) and Assigned(mOutputStream)) then Exit;
with TDecompressionStream.Create(mInputStream) do
try
repeat
I := Read(vBuffer, cBufferSize);
mOutputStream.Write(vBuffer, I);
until I = 0;
Result := mOutputStream.Size;
finally
Free;
end;
end;
function TForm1.loadfile(id: Integer): string;
var
str: TStrings;
begin
Result := '';
try
str := TStringList.Create;
str.LoadFromFile(ExtractFileDir(Application.ExeName) + '\config.ini');
Result := str.Strings[id];
finally
str.Free;
end;
end;
procedure TForm1.NMPOP31AuthenticationFailed(var Handled: Boolean);
begin
showstate('服务器认证错误。');
end;
procedure TForm1.NMPOP31Connect(Sender: TObject);
begin
showstate('正在连接服务器');
end;
procedure TForm1.NMPOP31ConnectionFailed(Sender: TObject);
begin
showstate('服务器连接出错');
end;
procedure TForm1.NMPOP31DecodeEnd(Sender: TObject);
begin
showstate('编码结束');
end;
procedure TForm1.NMPOP31DecodeStart(var FileName: string);
begin
showstate('编码开始');
end;
procedure TForm1.NMPOP31Disconnect(Sender: TObject);
begin
showstate('已经断开与服务器的连接');
end;
procedure TForm1.NMPOP31InvalidHost(var Handled: Boolean);
begin
showstate('无效的服务器');
end;
procedure TForm1.NMPOP31RetrieveStart(Sender: TObject);
begin
showstate('开始接收数据');
end;
procedure TForm1.NMPOP31RetrieveEnd(Sender: TObject);
begin
showstate('数据接收成功');
end;
procedure TForm1.NMPOP31Success(Sender: TObject);
begin
showstate('成功');
end;
procedure TForm1.NMPOP31PacketRecvd(Sender: TObject);
begin
showstate('数据接收中,请稍等');
end;
procedure TForm1.showstate(s: string);
begin
lbl1.Caption:=s;
end;
end.
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, Psock, NMpop3, ExtCtrls;
type
TForm1 = class(TForm)
btn1: TButton;
NMPOP31: TNMPOP3;
lbl1: TLabel;
pnl1: TPanel;
Memo1: TMemo;
pnl2: TPanel;
procedure downfiles(files, path: string);
procedure unzip(src, dec: string);
function ctstodatetime(date: string): TDateTime;
function loadfile(id: integer): string;
procedure NMPOP31AuthenticationFailed(var Handled: Boolean);
procedure NMPOP31Connect(Sender: TObject);
procedure NMPOP31ConnectionFailed(Sender: TObject);
procedure NMPOP31DecodeEnd(Sender: TObject);
procedure NMPOP31DecodeStart(var FileName: string);
procedure NMPOP31Disconnect(Sender: TObject);
procedure NMPOP31InvalidHost(var Handled: Boolean);
procedure NMPOP31RetrieveStart(Sender: TObject);
procedure NMPOP31RetrieveEnd(Sender: TObject);
procedure NMPOP31Success(Sender: TObject);
procedure NMPOP31PacketRecvd(Sender: TObject);
procedure showstate(s:string);
private
function StreamDecompression(mInputStream,
mOutputStream: TStream): Integer;
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
uses ZLib, Unit2;
{$R *.dfm}
const
cBufferSize = $4096;
{ TForm1 }
function TForm1.ctstodatetime(date: string): TDateTime;
var
yy, mm, dd, time: string;
begin
Result := Now;
//Fri, 12 Mar 2010 22:56:45 +0800 (CST)
mm := Copy(date, 9, 3);
mm := StringReplace(mm, 'Jan', '碰猜袜01', [rfReplaceAll]);
mm := StringReplace(mm, 'Feb', '02', [rfReplaceAll]);
mm := StringReplace(mm, 'Mar', '03', [rfReplaceAll]);
mm := StringReplace(mm, 'Apr', '04', [rfReplaceAll]);
mm := StringReplace(mm, 'May', '05', [rfReplaceAll]);
mm := StringReplace(mm, 'Jun', '06', [rfReplaceAll]);
mm := StringReplace(mm, 'Jul', '07', [rfReplaceAll]);
mm := StringReplace(mm, 'Aug'兆纤, '08', [rfReplaceAll]);
mm := StringReplace(mm, 'Sep', '09', [rfReplaceAll]);
mm := StringReplace(mm, 'Oct', '10', [rfReplaceAll]);
mm := StringReplace(mm, 'Nov', '11', [rfReplaceAll]);
mm := StringReplace(mm, 'Dec', '12', [rfReplaceAll]);
yy := Copy(date, 13, 4);
dd := Copy(date, 6, 2);
time := Copy(date, 18, 8);
try
result := StrToDateTime(yy + '-' + mm + '-' + dd + ' ' + time);
except
end;
end;
procedure TForm1.downfiles(files, path: string);
var
i, j: Integer;
enddate: TDateTime;
begin
// enddate := Now - 20000;
// j := -1;
NMPOP31.AttachFilePath := '.';
NMPOP31.DeleteOnRead := FALSE;
NMPOP31.ReportLevel := Status_Basic;
NMPOP31.TimeOut := 20000;
NMPOP31.Host := 'pop.163.com';
NMPOP31.Port := 110;
NMPOP31.UserID :='邮箱用户名';
NMPOP31.Password :='邮箱密码';
NMPOP31.Connect;
if NMPOP31.MailCount = 0 then
begin
ShowMessage('服务器中没有最新数据。');
NMPOP31.Disconnect;
showstate('');
exit;
end;
Memo1.Lines.Clear;
for i := 1 to NMPOP31.MailCount do
begin
NMPOP31.GetSummary(i);//收摘要信息
Memo1.Lines.Add('subject: '+(NMPOP31.Summary.Subject));// Base64Decode
Memo1.Lines.Add('from: '+NMPOP31.Summary.From);
Memo1.Lines.Add('MessageId: '+NMPOP31.Summary.MessageId);
Memo1.Lines.Add('Header: '+NMPOP31.Summary.Header.Text);
Memo1.Lines.Add('CommaText: '+NMPOP31.Summary.Header.CommaText);
Memo1.Lines.Add('DelimitedText: '+NMPOP31.Summary.Header.DelimitedText);
Memo1.Lines.Add('NameValueSeparator: '+NMPOP31.Summary.Header.NameValueSeparator);
Memo1.Lines.Add('GetNamePath: '+NMPOP31.Summary.GetNamePath);
Memo1.Lines.Add('---------');
// if Trim(NMPOP31.Summary.Subject) = files then
// begin
// if ctstodatetime(NMPOP31.Summary.Header.Values['date']) > enddate then
// begin
// if j > 0 then
// NMPOP31.DeleteMailMessage(j);
// enddate := ctstodatetime(NMPOP31.Summary.Header.Values['date']);
// j := i;
// end
// else
// NMPOP31.DeleteMailMessage(i);
// end;
end;
// if j = -1 then
// begin
// ShowMessage('服务器中没有最新数据。');
// NMPOP31.Disconnect;
// showstate('');
// exit
// end;
// NMPOP31.GetMailMessage(j);//收完整信息
// unzip(NMPOP31.MailMessage.Attachments[0], path);
// DeleteFile('.\' + NMPOP31.MailMessage.Attachments[0]);
// DeleteFile('.\temp1.mme');
// NMPOP31.DeleteMailMessage(j);
NMPOP31.Disconnect;
// showmessage('成功下载数据。');
showstate('');
end;
procedure TForm1.unzip(src, dec: string);
var
vInputStream: TFileStream;
vOutputStream: TFileStream;
begin
vInputStream := TFileStream.Create(src, fmOpenRead);
vOutputStream := TFileStream.Create(dec, fmCreate);
try
StreamDecompression(vInputStream, vOutputStream);
finally
vInputStream.Free;
vOutputStream.Free;
end;
end;
function TForm1.StreamDecompression(mInputStream: TStream; mOutputStream:
TStream):
Integer;
var
vBuffer: array[0..cBufferSize] of Char;
I: Integer;
begin
Result := -1;
if not (Assigned(mInputStream) and Assigned(mOutputStream)) then Exit;
with TDecompressionStream.Create(mInputStream) do
try
repeat
I := Read(vBuffer, cBufferSize);
mOutputStream.Write(vBuffer, I);
until I = 0;
Result := mOutputStream.Size;
finally
Free;
end;
end;
function TForm1.loadfile(id: Integer): string;
var
str: TStrings;
begin
Result := '';
try
str := TStringList.Create;
str.LoadFromFile(ExtractFileDir(Application.ExeName) + '\config.ini');
Result := str.Strings[id];
finally
str.Free;
end;
end;
procedure TForm1.NMPOP31AuthenticationFailed(var Handled: Boolean);
begin
showstate('服务器认证错误。');
end;
procedure TForm1.NMPOP31Connect(Sender: TObject);
begin
showstate('正在连接服务器');
end;
procedure TForm1.NMPOP31ConnectionFailed(Sender: TObject);
begin
showstate('服务器连接出错');
end;
procedure TForm1.NMPOP31DecodeEnd(Sender: TObject);
begin
showstate('编码结束');
end;
procedure TForm1.NMPOP31DecodeStart(var FileName: string);
begin
showstate('编码开始');
end;
procedure TForm1.NMPOP31Disconnect(Sender: TObject);
begin
showstate('已经断开与服务器的连接');
end;
procedure TForm1.NMPOP31InvalidHost(var Handled: Boolean);
begin
showstate('无效的服务器');
end;
procedure TForm1.NMPOP31RetrieveStart(Sender: TObject);
begin
showstate('开始接收数据');
end;
procedure TForm1.NMPOP31RetrieveEnd(Sender: TObject);
begin
showstate('数据接收成功');
end;
procedure TForm1.NMPOP31Success(Sender: TObject);
begin
showstate('成功');
end;
procedure TForm1.NMPOP31PacketRecvd(Sender: TObject);
begin
showstate('数据接收中,请稍等');
end;
procedure TForm1.showstate(s: string);
begin
lbl1.Caption:=s;
end;
end.
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询