发邮件的问题,急!急!(100分)

  • 主题发起人 主题发起人 sum_z_x
  • 开始时间 开始时间
S

sum_z_x

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么用delphi写发邮件的,内容,邮件地址都在delphi中写.急急.
 


unit Unit1;

interface

uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,StdCtrls, Psock, NMsmtp, ComCtrls;

type
TForm1 = class(TForm)
NMSMTP1: TNMSMTP;
Button1: TButton;
StatusBar1: TStatusBar;
Edit1: TEdit;
Label2: TLabel;
Label3: TLabel;
Edit2: TEdit;
Label4: TLabel;
Edit3: TEdit;
Label5: TLabel;
Edit4: TEdit;
Label6: TLabel;
Memo1: TMemo;
Label7: TLabel;
Edit5: TEdit;
Label1: TLabel;
Edit6: TEdit;
Label8: TLabel;
procedure Button1Click(Sender: TObject);
procedure NMSMTP1Connect(Sender: TObject);
procedure NMSMTP1InvalidHost(var Handled: Boolean);
procedure NMSMTP1ConnectionFailed(Sender: TObject);
procedure NMSMTP1Status(Sender: TComponent; Status: String);
procedure NMSMTP1SendStart(Sender: TObject);
procedure NMSMTP1Success(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

//BaseTable为BASE64码表
const BaseTable:string='ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=';

var
Form1: TForm1;
AuthSucc:boolean;// 是否需要密码验证
function DecodeBase64(Source:string):string; //解码函数
function FindInTable(CSource:char):integer; //
function EncodeBase64(Source:string):string; //编码函数
implementation
{$R *.DFM}

//
function FindInTable(CSource:char):integer;
begin
result:=Pos(string(CSource),BaseTable)-1;
end;
////

function DecodeBase64(Source:string):string;
var
SrcLen,Times,i:integer;
x1,x2,x3,x4,xt:byte;
begin
result:='';
SrcLen:=Length(Source);
Times:=SrcLen div 4;
for i:=0 to Times-1 do
begin
x1:=FindInTable(Source[1+i*4]);
x2:=FindInTable(Source[2+i*4]);
x3:=FindInTable(Source[3+i*4]);
x4:=FindInTable(Source[4+i*4]);
x1:=x1 shl 2;
xt:=x2 shr 4;
x1:=x1 or xt;
x2:=x2 shl 4;
result:=result+chr(x1);
if x3= 64 then break;
xt:=x3 shr 2;
x2:=x2 or xt;
x3:=x3 shl 6;
result:=result+chr(x2);
if x4=64 then break;
x3:=x3 or x4;
result:=result+chr(x3);
end;
end;
/////

function EncodeBase64(Source:string):string;
var
Times,LenSrc,i:integer;
x1,x2,x3,x4:char;
xt:byte;
begin
result:='';
LenSrc:=length(Source);
if LenSrc mod 3 =0 then
Times:=LenSrc div 3
else
Times:=LenSrc div 3 + 1;
for i:=0 to times-1 do
begin
if LenSrc >= (3+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(Ord(Source[2+i*3]) shl 2) and 60;
xt:=xt or (ord(Source[3+i*3]) shr 6);
x3:=BaseTable[xt+1];
xt:=(ord(Source[3+i*3]) and 63);
x4:=BaseTable[xt+1];
end
else if LenSrc>=(2+i*3) then
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
xt:=xt or (ord(Source[2+i*3]) shr 4);
x2:=BaseTable[xt+1];
xt:=(ord(Source[2+i*3]) shl 2) and 60;
x3:=BaseTable[xt+1];
x4:='=';
end else
begin
x1:=BaseTable[(ord(Source[1+i*3]) shr 2)+1];
xt:=(ord(Source[1+i*3]) shl 4) and 48;
x2:=BaseTable[xt+1];
x3:='=';
x4:='=';
end;
result:=result+x1+x2+x3+x4;
end;
end;

//////////
procedure TForm1.Button1Click(Sender: TObject);
//var MailTo,MailBody:TStringList;
begin
Nmsmtp1.Host :=Edit1.Text;
nmsmtp1.Port :=25;
nmsmtp1.UserID :=Edit2.Text;//发信人的用户名,必须是真实的
nmsmtp1.ReportLevel :=1;
Nmsmtp1.TimeOut :=10000;
nmsmtp1.Connect ; ///连接
if AuthSucc=true then ////验证成功
begin
nmsmtp1.PostMessage.FromAddress:=Edit4.Text; //发信人的电子邮件地址
nmsmtp1.PostMessage.ToAddress.Text :=Edit5.Text;
nmsmtp1.PostMessage.Body.Text:=Memo1.Text;
nmsmtp1.PostMessage.Subject :=Edit6.Text;
nmsmtp1.SendMail;
end;
end;

procedure TForm1.NMSMTP1Connect(Sender: TObject);
begin
//////连接成功,下面用户认证过程
StatusBar1.SimpleText:=nmsmtp1.Status;
if nmsmtp1.ReplyNumber = 250 then
StatusBar1.SimpleText:=nmsmtp1.Transaction('auth login'); //开始认证
if nmsmtp1.ReplyNumber =334 then //返回值为334,让你输入用BASE64编码后的用户名
StatusBar1.SimpleText:=nmsmtp1.Transaction(EncodeBase64(Edit2.Text));
if nmsmtp1.ReplyNumber =334 then // 返回值为334,让你输入用BASE64编码后的用户密码
StatusBar1.SimpleText:=nmsmtp1.Transaction(EncodeBase64(Edit3.Text));
if nmsmtp1.ReplyNumber =235 then
begin
StatusBar1.SimpleText:='successful';
AuthSucc:=true;
end;
end;

procedure TForm1.NMSMTP1InvalidHost(var Handled: Boolean);
begin
StatusBar1.SimpleText :='Invalid Host';
end;
procedure TForm1.NMSMTP1ConnectionFailed(Sender: TObject);
begin
StatusBar1.SimpleText :='connect failed';
end;
procedure TForm1.NMSMTP1Status(Sender: TComponent; Status: String);
begin
StatusBar1.SimpleText :=nmsmtp1.Status ;
end;
procedure TForm1.NMSMTP1SendStart(Sender: TObject);
begin
StatusBar1.SimpleText :='start send';
end;
procedure TForm1.NMSMTP1Success(Sender: TObject);
begin
StatusBar1.SimpleText:='send success!';
end;

end.
 
http://bbs.2ccc.com/upload/peng/GroupMailSRC.rar
 
有没有个附件啊.
 
Nmsmtp1.Host:edit1.text;
nmsmtp1.Port :=25;
nmsmtp1.ReportLevel :=1;
Nmsmtp1.TimeOut :=10000;
nmsmtp1.PostMessage.ToAddress.Text :=Edit5.Text;
nmsmtp1.PostMessage.Body.Text:=Memo1.Text;
nmsmtp1.PostMessage.Subject :=Edit6.Text;
以上这些各是什么意思.不好意思我是新手.
 
Nmsmtp1.Host:edit1.text; //SMTP服务器地址
nmsmtp1.Port :=25; /smtp服务器端口(一般是25
nmsmtp1.ReportLevel :=1;
Nmsmtp1.TimeOut :=10000; //超时时间(毫秒)
nmsmtp1.PostMessage.ToAddress.Text :=Edit5.Text;//收信地址
nmsmtp1.PostMessage.Body.Text:=Memo1.Text;//信件内容
nmsmtp1.PostMessage.Subject :=Edit6.Text;//信件主题
 
为什么联接时好像联不上一直出错.错误提示:
project project1.exe raised exception class ESockerror with message'connection timed out'.process stopped.use step or run to continue.
 
连接超时,请检查网络
 
这个程序是ESMTP的
 
那要怎么办啊.
 
把Indy的例子仔细研究下,你就明白了
 
好的,谢谢你们两位!
 
SMTP邮件服务器要对发送邮件的用户进行身份验证,要给出用户名和密码信息
否则无法发送 而D5的TNMSmtp没有“密码”属性,不能利用服务器发送邮件,否则会出现错误信息;有没有别的方法啊
 
多人接受答案了。
 
后退
顶部