delphi发邮件大一点的附件报错(我用delphi2006写了一个发送邮件的程序,但是发送不成功!提示:socket error #10054 connection reset by)

本文目录
- 我用delphi2006写了一个发送邮件的程序,但是发送不成功!提示:socket error #10054 connection reset by
- 在delphi程序运行时,报错
- Delphi问题
- DELPHI邮件发送的问题
- delphi 读邮件乱码
- delphi问题
- 关于Delphi的问题 , 老鸟请进!
- DELPHI 读取文本报错
- delphi高手进,关于UDP发送文件这块的问题
我用delphi2006写了一个发送邮件的程序,但是发送不成功!提示:socket error #10054 connection reset by
大哥,这个问题是说明你的Socket连接部分出错了。根本没到你发送邮件的那一步。
物理连接没有建立,当然是不对了,检查你的POP3或SMTP服务器的IP和端口号是否正确。
在delphi程序运行时,报错
试如下方法:
1、打开开始菜单找“运行”输入“C:\Windows\system32\msxml3.dll”、regsvr32、 C:\Windows\system32\msxml3.dll
2、如果上面的方法不行,把以下内容复制到文本文件中,存为1.bat,然后再双击运行此文件。
For %%i in (C:\windows\system32\*.dll) Do regsvr32.exe /s %%i
For %%i in (C:\windows\system32\*.ocx) Do regsvr32.exe /s %%i
Delphi问题
function TForm1.SendEmail: Boolean;
var
idattachment: TIdAttachment;
begin
Result:= false;
try
Msg.Clear;
Msg.Body.Add(RzMemo1.Text); //邮件内容
Msg.From.Text:= RzEdit7.Text; //副标题
Msg.From.Name:= RzEdit3.Text; //发件人
Msg.Subject:= RzEdit4.Text; //标题
Msg.Recipients.EMailAddresses := RzEdit2.Text;// 发送者地址
if RzEdit5.Text 《》 ’’ then
idattachment:= tidattachment.Create(Msg.MessageParts, RzEdit5.Text);
SMTP.AuthenticationType:=atLogin;
SMTP.Host:= RzEdit6.Text;
SMTP.Username:= RzEdit7.Text;
SMTP.Password:= RzEdit8.Text;
SMTP.Port := 25;
SMTP.Connect;
SMTP.Send(Msg);
SMTP.Disconnect;
except
on E: Exception do
begin
Application.MessageBox(Pchar(’发送邮件失败:’ + E.message), ’szy’, MB_OK or MB_ICONINFORMATION);
SMTP.Disconnect;
exit;
end;
end;
Application.MessageBox(Pchar(’发送邮件成功!’), ’szy’, MB_OK or MB_ICONINFORMATION);
Result:= true;
end;
---------------------------
Msg.Recipients.EMailAddresses 的地址用’;’分隔就行了,也就是memo里的收件人地址用分号分隔
DELPHI邮件发送的问题
没有添加引用...
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, IdMessage, IdTCPConnection, IdTCPClient, IdMessageClient,
IdSMTP, StdCtrls, IdAntiFreezeBase, IdAntiFreeze, IdBaseComponent,
IdComponent, IdUDPBase, IdUDPClient, IdDNSResolver;
delphi 读邮件乱码
邮件解码函数
function CheckTxt(const src: string): string;
var
i,pos1,pos2,pos3:integer;
post:string;
srclist:TStringList;
function Decoder(const s:string):string;
var
s1,s2,s3: integer;
t,v: string;
Encoding: char;
hex,step: integer;
a1: array of byte;
b1: array of byte;
j: integer;
byte_ptr,real_bytes: integer;
tempedit:TEdit;
begin
s1:=Pos(’=?’,s);
s2:= 1 ;
hex:= 0 ;
if s1》0 then
for s2:=Length(s)-1 downto 1 do
if Copy(s,s2,2)=’?=’ then Break;
if (s1=0) or (s2=1) then
begin
Result:=s;
Exit;
end;
t:=Copy(s,s1+2,s2-2-s1);
s3:=Pos(’?’,t);
Delete(t,1,s3);
if(t=’’)then
begin
Result:= s;
Exit ;
end ;
Encoding:=t;
Delete(t,1,2);
v:=’’;
step:=0;
case Encoding of
’Q’:
while t《》’’ do
begin
case step of
0:
begin
case t of
’_’: v:=v+’ ’;
’=’: step:=1;
else v:=v+t;
end;
end;
1:
begin
if t)-Ord(’0’))*16
else hex:=(Ord(t)-55)*16;
step:=2;
end;
2:
begin
if t)-Ord(’0’))
else hex:=hex+Ord(t)-55;
v:=v+Chr(hex);
step:=0;
end;
end;
Delete(t,1,1);
end;
’B’:
begin
byte_ptr:=0;
for j:=1 to Length(t) do
begin
Inc(byte_ptr);
case t of
’A’..’Z’: a1)-65;
’a’..’z’: a1)-71;
’0’..’9’: a1)+4;
’+’: a1:=62;
’/’: a1:=63;
’=’: a1:=64;
end;
if byte_ptr=4 then
begin
byte_ptr:=0;
real_bytes:=3;
if a1=64 then real_bytes:=0;
if a1=64 then
begin
a1:=0;
a1:=0;
real_bytes:=1;
end;
if a1=64 then
begin
a1:=0;
real_bytes:=2;
end;
b1 div 16);
b1div 4);
b1;
if (real_bytes》0) then
v:= v + chr(b1) ;
if (real_bytes》1) then
v:= v + chr(b1) ;
if (real_bytes》2) then
v:= v + chr(b1) ;
end;
end;
end;
end;
Result:=Copy(s,1,s1-1)+v+Copy(s,s2+2,999);
tempedit:=TEdit.Create(nil);
try
tempedit.Width:=0;
tempedit.Height:=0;
tempedit.Visible:=True;
tempedit.Text:=Result;
Result:=tempedit.Text;
finally
FreeAndNil(tempedit);
end;
if Pos(’***SPAM***’,Result)》0 then
result:=copy(result,pos(’-’,result)+1,length(result)-pos(’-’,result));
end;
begin
pos1:=Pos(’=?’,src);
pos2:= 1 ;
if pos1》0 then
for pos2:=Length(src)-1 downto 1 do
if Copy(src,pos2,2)=’?=’ then Break;
if (pos1=0) or (pos2=1) then
begin
Result:=src;
Exit;
end;
post:=Copy(src,pos1+2,pos2-2-pos1);
pos3:=Pos(’?’,post);
Delete(post,1,pos3);
if(post=’’)then
begin
Result:=src;
Exit ;
end ;
srclist:=TStringList.Create;
try
srclist.Clear;
StrtoStrlist(’ ’,src,srclist);
Result:=’’;
for i:=0 to srclist.Count-1 do
begin
post:=srclist.Strings;
Result:=Result+Decoder(post);
end;
finally
srclist.Free;
end;
end;
delphi问题
memo1.lines:Tstrings
edit1.text:Tcaption
当然不一样了
你试试这样
var
str:Tstrings;
str.add(edit1.text);
IdMessage1.Body.Assign((str));
关于Delphi的问题 , 老鸟请进!
下边这个代码完全可以!试着按照自己实际应用修改一下吧!
发送主要用两个控件:TIdMessage,TIdSMTP;
定义:
MailMessage: TIdMessage;
Mail: TIdSMTP;
实现举例:
procedure TForm1.Button1Click(Sender: TObject);
begin
if Mail.Connected then Mail.Disconnect;
Mail.Username := ’’; //发件人用户名
Mail.Password := ’’; // 发件人密码
Mail.Host := ’’; //SMTP地址 这个地址要设置正确
Mail.Port := 25; //端口
Mail.AuthenticationType := atLogin;
MailMessage.Subject := ’test标题’; //标题
MailMessage.Body.Text := ’test内容’; //内容
MailMessage.From.Name := ’’; //发件人姓名
MailMessage.From.Address := ’’; //发件人地址
MailMessage.ReplyTo.EMailAddresses := ’’; //发件人地址
MailMessage.Priority := TIdMessagePriority(1); //身份验证类型
TIdAttachment.Create(MailMessage.MessageParts, ’C:\Documents and Settings\Administrator\桌面\mail.txt’); //附件地址
MailMessage.Recipients.EMailAddresses := ’’; // 收件人地址
MailMessage.From.Address := ’’; //发件人地址
try
Mail.Connect;
Mail.Authenticate;
Mail.Send(MailMessage);
finally
Mail.Disconnect;
end;
end;
===============================================
对于需要认证的服务器应该这样做
procedure TForm1.Button2Click(Sender: TObject);
begin
begin
MemoInfo.Clear;
//1:对所必须要的信息进行进行检验
//校验服务器属性
if (Trim(HostName.Text)=’’) or (Trim(HostPort.Text)=’’) then
begin
ShowMessage(’请设置所要连接的SMTP服务器属性!’);
HostPort.Text:=’25’;
HostName.SetFocus;
Exit;
end;
//检测地址信息
if (Trim(EditFrom.Text)=’’) or (Trim(EditTo.Text)=’’) then
begin
ShowMessage(’请输入收信人或者发信人地址!’);
EditFrom.SetFocus ;
Exit;
end;
//用户账号检验
if (Trim(EditUser.Text)=’’) or (Trim(EditPass.Text)=’’) then
begin
ShowMessage(’请正确输入用户登录帐号和密码!’);
EditUser.SetFocus;
Exit;
end;
//对MailMessage属性进行赋值
with MailMessage do
begin
Subject := ’test’; //邮件主题
Body.Assign(MemoMesg.Lines);//邮件正文
From.Address:=Trim(EditFrom.Text); //发信人地址
Recipients.EMailAddresses := Trim(editTo.Text); //收件人地址
//CCList.EMailAddresses :=EditCC.Text;
//BCCList.EMailAddresses:=EditBCC.Text;
// for indexnum:=0 to AttachmentList.Items.Count do
// TIdAttachment.Create(MailMessage.MessageParts,);
end;
//设置连接到服务器属性
with IdSMTP do
begin
Host:=Trim(HostName.Text); //SMTP服务器地址
Port:=StrToInt(Trim(HostPort.Text)); //SMTP服务器端口
UserName:=Trim(EditUser.Text); //用户账号
Password:=Trim(EditPass.Text); // 用户密码
end;
//连接到服务器
MemoInfo.Lines.Add(’准备连接到服务器!’+HostName.Text);
try
IdSMTP.Connect(); //调用 Connect连接服务器
except //连接失败
begin
MemoInfo.Lines.Add(’无法连接到服务器!’+HostName.Text);
Exit;
end ;
end;
//身份验证
//检测SMTP服务器是否需要验证
if (IdSMTP.AuthSchemesSupported.IndexOf ( ’LOGIN’ ) 《》 -1) then
begin //服务器要求验证
MemoInfo.Lines.Add(’服务器要求验证’);
IdSMTP.AuthenticationType:=atlogin;
end
else
begin //服务器不要求验证
MemoInfo.Lines.Add(’服务器不需要验证’);
end;
MemoInfo.Lines.Add(’开始验证’);
try
if IdSMTP.Authenticate then //验证通过
MemoInfo.Lines.Add(’服务器验证通过’)
else
MemoInfo.Lines.Add(’服务器验证失败’); //验证失败
except
begin
MemoInfo.Lines.Add(’服务器验证失败’);
IdSMTP.Disconnect;
exit;
end;
end;
//发送信件
try
IdSMTP.Send(MailMessage);
except
MemoInfo.Lines.Add(’发送失败’);
end;
IdSMTP.Disconnect;
//发送完成
end;
end;
DELPHI 读取文本报错
前几天不是在Hi里已经跟你说用CopyFile先复制一个吗?还不行?
我记得给的是这个:
CopyFile(PChar(ExtractFilePath(Application.ExeName)+’error.log’),PChar(ExtractFilePath(Application.ExeName)+’errorbak.log’),False);
delphi高手进,关于UDP发送文件这块的问题
最简单的做法,可以在 if OpenDialog1.Execute then之前做一下检验,是否已经发送过一次,如果是,则提示,然后跳出,如果不是,运行发送过程,在发送过程完成之后,对该标志赋值。
if bPassSending then
begin
ShowMessage(’不能再次发送’);
exit;
end;
if OpenDialog1.Execute then
.....
发送完成之后
bPassSending := True;
end;

更多文章:
jquery动态添加表格行(如何通过jquery动态给表格添加一行)
2026年10月23日 00:30
cmake命令行参数(CMake (三)cmake 在工程中的用法)
2026年10月23日 00:00
linux数据备份命令(Linux系统下常用的数据备份方法有哪些)
2026年10月22日 23:20
executequery返回值(ExecuteQuery(sql)的返回值)
2026年10月22日 23:00
舍曲林吃了一周越来越严重(我母亲77岁,服用舍曲林一周,开始半片,4天后改为1片,第三天开始失眠,第四天出现乏力、食欲下降,)
2026年10月22日 21:00



