200分问个发信的,问题,引用其它贴,分从另外贴上转!!(100分)

  • 主题发起人 主题发起人 cntiny
  • 开始时间 开始时间
C

cntiny

Unregistered / Unconfirmed
GUEST, unregistred user!
unit Unit1;

interface

uses
SysUtils,winsock,Forms, StdCtrls, Classes, Controls;

type
TForm1 = class(TForm)
Edit1: TEdit;
Button1: TButton;

procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public

{ Public declarations }
end;

var
Form1: TForm1;

implementation
const
CRLF=#13#10;
{$R *.dfm}
function StartNet(host:string;port:integer):integer;
var
wsadata:twsadata;
fsocket:integer;
SockAddrIn:TSockAddrIn;
err:integer;
begin
//为网络连接作好准备(用winsock1.1以上版本)
WSAStartup($0101,WSAData);
//创建一个客户端套接字(Client Socket,用SOCK_STREAM,即TCP协义)
FSocket := socket(PF_INET, SOCK_STREAM,IPPROTO_IP);
//初始化网络数据
SockAddrIn.sin_addr.s_addr:=inet_addr(PChar(host));
SockAddrIn.sin_family := PF_INET;
SockAddrIn.sin_port :=htons(port);
//客户端向smtp进行连接
repeat
err:=connect(FSocket,SockAddrIn, SizeOf(SockAddrIn));
until err=0;
//
Result:=FSocket;
end;
//以下是网络关闭的过程
procedure StopNet(Fsocket:integer);
begin
//发信结束,关闭客户端套接字(Close Client Socket)
closesocket(FSocket);
//清除网络参数
WSACleanup;
end;
//下面是个发送数据包的过程
function SendData(FSocket:integer;SendStr:string):integer;
var
DataBuf:array[0..1024] of char;
begin
//读取网络数据
recv(FSocket,DataBuf,1024,0);
//将网络数据写入主窗口的标题中,提示用户正在发信过程中

//WriteCaption(handle,DataBuf);
//向网络发送数据
strcopy(DataBuf,pchar(SendStr));
send(FSocket,DataBuf,strlen(DataBuf),MSG_DONTROUTE);
Result:=0;
end;

//下面是个发信的过程
procedure TForm1.Button1Click(Sender: TObject);
var SendBody:string;
FSocket:integer;dest:string;
begin
FSocket:=StartNet('smtp.elong.com',25);
SendData(FSocket,'EHLO'+CRLF);
SendData(FSocket,'dXNlcg=='+CRLF);// 编码后的用户名:'user'
SendData(FSocket,'cGFzc3dvcmQ='+CRLF); // 编码后的:'password'
SendData(FSocket,'MAIL FROM:<user@elong.com>'+CRLF);
dest:='user@elong.com';
SendData(FSocket,'RCPT TO: <'+dest+'>'+CRLF);
SendData(FSocket,'DATA'+CRLF);
SendBody:='From:"bome 2001"<cnxxx_007@elong.com>'+CRLF
+'To:"bome 2001"<cnxxx_007@elong.com>'+CRLF
+'Subject:<cnxxx_007@elong.com>'+CRLF
+CRLF
+'Hello World.'+CRLF
+'.'+CRLF;
SendData(FSocket,SendBody);
//第六步:发结QUIT指令,表示发信过程结束
SendData(FSocket,'QUIT'+CRLF);
StopNet(Fsocket);
end;




end.



我为什么接不到信呀!!!!!!!!!!!!!!

用telnet模拟发,为什么也接不到呀!!!!!

 
新建一个form 加上indy 面板上的 IdMsgSend,TidSMTP控件
ses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ExtCtrls, IdBaseComponent, IdComponent,
IdTCPConnection, IdTCPClient, IdMessageClient, IdSMTP, IdMessage,
ComCtrls, KvLabel;

type
TFormsmtp = class(TForm)
Panel1: TPanel;
Label1: TLabel;
Label2: TLabel;
Label3: TLabel;
Edit1: TEdit;
Edit2: TEdit;
Edit3: TEdit;
Memo1: TMemo;
Button1: TButton;
SMTP: TIdSMTP;
IdMsgSend: TIdMessage;
ProgressBar1: TProgressBar;
Label6: TLabel;
KvLabel1: TKvLabel;
KvLabel2: TKvLabel;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure SMTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
procedure SMTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
procedure FormCreate(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Formsmtp: TFormsmtp;

implementation

uses zhuce, fununit, about;

{$R *.dfm}
procedure TFormsmtp.Button1Click(Sender: TObject);
var
i: integer;
begin
if Edit1.Text = '' then
begin
MessageDlg('用户信箱不能为空!', mtInformation,
[mbOk], 0);
exit;
end;
if not IsEMail(edit1.Text) then
begin
MessageDlg('用户信箱不合法!', mtInformation,
[mbOk], 0);
exit;
end;
if Edit2.Text = '' then
begin
MessageDlg('请输入用户姓名!', mtInformation,
[mbOk], 0);
exit;
end;

SMTP.Username := 'XXX@21cn.com'; //帐户
SMTP.Password := '12345678'; //密码
{General setup}
SMTP.Host := 'smtp.21cn.com';
SMTP.Port := 25;
try
SMTP.Connect;
except
Showmessage('您可能没有连上互联网,获取注册号码失败!');
Exit;
end;
try
with IdMsgSend do
begin
body.Clear;
Body.Add('系统注册码' + #10#13); //内容
Body.add('用户信箱:' + edit1.Text + #10#13);
Body.add('用户姓名:' + edit2.Text + #10#13);
Body.add('使用单位:' + edit3.Text + #10#13);
for i := 0 to memo1.lines.count - 1 do
Body.add(memo1.Lines + #10#13);
From.Text := edit1.text;
Recipients.EMailAddresses := 'master@datacn.com'; //收件人
Subject := '申请系统注册码'; //主题
end;
SMTP.Send(IdMsgSend);
finally
SMTP.Disconnect;
end;
end;

procedure TFormsmtp.SMTPWorkBegin(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCountMax: Integer);
begin
ProgressBar1.Position := 20;
end;

procedure TFormsmtp.SMTPWorkEnd(Sender: TObject; AWorkMode: TWorkMode);
begin
ProgressBar1.Position := 100;
showmessage('发送完成');
ProgressBar1.Position := 0;
close;
end;

procedure TFormsmtp.FormCreate(Sender: TObject);
begin
Memo1.Lines.Add('我要申请注册码' + #10#13);

end;

procedure TFormsmtp.Button2Click(Sender: TObject);
begin
close;
end;
 
大哥:
IdMsgSend这个控件在哪呀?
 
可能在 D6 D7
 
下面这个过程只是一股脑的给smtp服务器发信息,服务器应答不管不顾能行么?

procedure TForm1.Button1Click(Sender: TObject);
var SendBody:string;
FSocket:integer;dest:string;
begin
FSocket:=StartNet('smtp.elong.com',25);
SendData(FSocket,'EHLO'+CRLF);
SendData(FSocket,'dXNlcg=='+CRLF);// 编码后的用户名:'user'
SendData(FSocket,'cGFzc3dvcmQ='+CRLF); // 编码后的:'password'
SendData(FSocket,'MAIL FROM:<user@elong.com>'+CRLF);
dest:='user@elong.com';
SendData(FSocket,'RCPT TO: <'+dest+'>'+CRLF);
SendData(FSocket,'DATA'+CRLF);
SendBody:='From:"bome 2001"<cnxxx_007@elong.com>'+CRLF
+'To:"bome 2001"<cnxxx_007@elong.com>'+CRLF
+'Subject:<cnxxx_007@elong.com>'+CRLF
+CRLF
+'Hello World.'+CRLF
+'.'+CRLF;
SendData(FSocket,SendBody);
//第六步:发结QUIT指令,表示发信过程结束
SendData(FSocket,'QUIT'+CRLF);
StopNet(Fsocket);
end;

 
到这里就死循环了,连接不上

//客户端向smtp进行连接
repeat
err:=connect(FSocket,SockAddrIn, SizeOf(SockAddrIn));
until err=0;
 
加个时间控制!
 
jsxjd: 不知道为什么链接不上,楼主贴的程序实现有问题么?
 
不行呀!!
 
indy是delphi7的标准控件
indy 面板上的 IdMsgSend,TidSMTP控件
关于indy的相关资料下载
http://www.playicq.com
 
多人接受答案了。
 
后退
顶部