IdSmtp电子邮件发送电子邮件失败,请教高手!

agenchen 2004-05-07 04:34:18
本人写了一个电子邮件发送程序,可是,老是出现错误,求高手帮忙解决:
procedure TForm1.Button1Click(Sender: TObject);
begin
with IdMessage1 do
begin
Body.Text:=Memo1.Text;
From.Address:='maplechen2002@163.com';
Recipients.EMailAddresses:='maplechen@163.com';
Subject:='实验邮件!';
end;
with IdSmtp1 do
begin
Host:='smtp.163.com';
Username:='maplechen2002@163.com';
Password:='********'; //这里是我的密码
Connect(-1);
Send(Idmessage1);
Disconnect;
end;
ShowMessage('发送完毕!');
end;


可是却出现了
You are not authorized to send mail as <MAIL FROM:<maplechen2002@163.com>>,authentication is required
的错误,请问,这个问题该如何解决阿 ?
是不是在IdMessage1中也要加什么密码的阿?
要是要加,那又该如何加呢?
我没有看到什么
IdMessage1.Password什么的,请高手指教!!
...全文
428 8 打赏 收藏 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
flyboyhua 2004-06-15
  • 打赏
  • 举报
回复
with F_sendmail.IdMsg do
begin
F_sendmail.idSMTP.Username := vSmtpid;
F_sendmail.idSMTP.Password :=vpassword;
F_sendmail.idSMTP.Host :=vSmtphost;
F_sendmail.idSMTP.Port := vSmtpPort;
Body.Assign(F_sendmail.Memcontent.Lines);
From.Text :=vmail;
Subject := F_sendmail.etitle.Text; { Subject: header }
// F_sendmail.idSMTP.AuthenticationType := atLogin; {Simple Login}
F_sendmail.IdSMTP.AuthenticationType := atNone;

F_sendmail.IdSMTP.Connect;

try
if
F_sendmail.IdSMTP.AuthSchemesSupported.IndexOf('LOGIN')>-1 then
begin
F_sendmail.IdSMTP.AuthenticationType := atLogin;
if not F_sendmail.IdSMTP.Authenticate then
begin
showmessage('身份验证失败!!!!');
F_sendmail.IdSMTP.Disconnect;
exit;
end;
end;
F_sendmail.idmsg.Recipients.EMailAddresses:=listbox2.Items[i];
F_sendmail.idSMTP.Send(F_sendmail.IdMsg);
end;
lhz888 2004-05-08
  • 打赏
  • 举报
回复
用户名用:maplechen2002试试
iLvXX1981 2004-05-08
  • 打赏
  • 举报
回复
查看delphi的帮助,IdSmtp并没有身份验证机制,对于那些需要身份验证的smtp服务器需要通过其他的方法(我现在也还没搞定~~),不过如果你安装了瑞星邮件监控,那么发送时他会弹出身份验证窗口,输入正确的用户名和密码,邮件就能正常发送,不过这种方法显然不是很好,如果能通过底层直接发送socket进行通讯,问题应该可以解决,正在学习中……
sunseave 2004-05-08
  • 打赏
  • 举报
回复
with IdMessage do
begin
Clear;
From.Address := CboSender.Text;
// From.Name := edit1.text; //自動產生成 name<e_mail>
Recipients.EMailAddresses := edtRecipient.Text; {收件人}
Priority := TIdMessagePriority(2); // 0-4, 0表示最高優先順序
CCList.EMailAddresses := edtCopyAdd.Text; {CC}
BccList.EMailAddresses := edtConfidential.Text; {BBC}
ReceiptRecipient.Text := From.Text; //要寄件回涵
Subject := edtSubject.Text; { Subject: header }

IdMessage.MessageParts.Clear;
Tidtext.Create(IdMessage.MessageParts);
with Tidtext.Create(IdMessage.MessageParts, mmoMessageText.Lines) do
begin
ContentType := 'text/html';
end;
for i := 0 to Listbox1.Items.Count - 1 do
TIdAttachment.Create(IdMessage.MessageParts, Listbox1.Items[i])
end;
with IdSMTP do
begin
(FDmdMant as TDmdOAMail).QrySmtpServer.Active := False;
(FDmdMant as TDmdOAMail).QrySmtpServer.ParamByName('RecAdd').AsString := CboSender.Text;
(FDmdMant as TDmdOAMail).QrySmtpServer.Active := True;
Host := (FDmdMant as TDmdOAMail).QrySmtpServer.FieldByName('SMTPServer').AsString;
UserName := (FDmdMant as TDmdOAMail).QrySmtpServer.FieldByName('AccountName').AsString; //請注意indy81以上為username
Password := (FDmdMant as TDmdOAMail).QrySmtpServer.FieldByName('Password').AsString;
try
sbMain.SimpleText := '連線測試中...請稍候';
application.ProcessMessages;
idsmtp.Connect;
sbMain.SimpleText := '連線測試成功!';
send(IdMessage);
application.ProcessMessages;

sbMain.SimpleText := '邮件已发送成功!';

idsmtp.Disconnect;
btnSendMail.Enabled := false; //正確後將按鈕disabled,提供下一頁按鈕的判斷,可以避免重複測試
iLvXX1981 2004-05-08
  • 打赏
  • 举报
回复
楼上的,我尝试过把IDSMTP1里的AuthenticationType属性改成atLogin,
可是在验证的时候if self.IdSMTP.Authenticate then 总是出错,
能否把你的贴出来,让我们学习一下呢?

现在用NMSMTP完成了一个带身份验证的,不过还有bug,对于企业邮箱不能带附件:
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.NMSMTPConnect(Sender: TObject);
var
AuthOK: Boolean;
begin
AuthOK := False;
NMSMTP.Transaction('auth login');
if NMSMTP.ReplyNumber <> 500 then
begin
if NMSMTP.ReplyNumber = 334 then
begin
NMSMTP.Transaction(EncodeBase64('myUseName')); // UserName
NMSMTP.Transaction(EncodeBase64('****')); // Password
end;
if NMSMTP.ReplyNumber = 235 then
self.Memo2.Lines.Add('验证成功!')
else
self.Memo2.Lines.Add('验证失败!');
end
else
self.Memo2.Lines.Add('该SMTP服务器无需用户验证。');

try
self.NMSMTP.PostMessage.FromAddress := 'myUseName@126.com';
self.NMSMTP.PostMessage.FromName := 'myUseName';
self.NMSMTP.PostMessage.Subject := 'test';
self.NMSMTP.PostMessage.ToAddress.Add(self.Edit1.Text);
self.NMSMTP.PostMessage.Attachments.AddStrings(self.lstbxAdditional.Items);
self.NMSMTP.PostMessage.Body.Assign(self.memo1.Lines);

self.NMSMTP.SendMail;
finally
self.NMSMTP.Disconnect;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
self.Memo2.Lines.Add('--使用NMSMTP发送邮件开始--');
self.NMSMTP.ClearParameters;
self.NMSMTP.UserID := 'myUseName';
self.NMSMTP.Port := 25;
self.NMSMTP.Host := 'smtp.126.com';

self.NMSMTP.Connect;
end;

该程序不能发送带附件的邮件到企业邮。
sunseave 2004-05-08
  • 打赏
  • 举报
回复
我也碰到过这个问题,只要把IDSMTP1里的AuthenticationType属性改成atLogin就行
cai21cn 2004-05-07
  • 打赏
  • 举报
回复
不好意思,写错了,是去掉不是支持
cai21cn 2004-05-07
  • 打赏
  • 举报
回复
支持username中的“@163.com”试试
内容概要:本文围绕【复现IEEE二区文献】基于状态空间表示与组件连接法的构网型逆变器统一小信号建模框架研究,提出了一种适用于多控制策略构网型逆变器的小信号建模方法。该方法结合状态空间建模理论与组件连接法(Component Connection Method),实现了对复杂逆变器系统动态特性的精确描述,尤其适用于分析系统在不同运行工况下的稳定性。通过Matlab代码实现,构建了包含控制环路、滤波器、锁相环等关键模块的完整小信号模型,并利用特征值分析与模态参与度评估系统稳定性,解决了传统建模方法在面对多时间尺度、强耦合非线性控制结构时建模困难、精度不足的问题。研究还探讨了关键控制参数对系统稳定边界的影响,为构网型逆变器的参数整定与优化设计提供了理论依据和技术支撑。; 适合人群:具备电力电子、自动控制理论基础,从事新能源发电、微电网、电力系统稳定性研究的研究生、科研人员及工程技术人员,尤其适合致力于高水平期刊论文复现与仿真实践的科研工作者。; 使用场景及目标:① 掌握构网型逆变器统一小信号建模的核心方法,复现IEEE二区高水平文献成果;② 理解状态空间法与组件连接法在复杂电力电子系统建模中的集成应用;③ 利用Matlab进行特征值分析与稳定性判据研究,支撑科研仿真与论文写作;④ 为多逆变器并联系统、微电网稳定性分析等课题提供建模工具与技术路线参考。; 阅读建议:建议读者结合Matlab代码与文中建模流程逐步调试,重点关注各子模块状态方程的推导与系统整体矩阵组装过程,深入理解控制参数对系统极点分布的影响规律,建议配合其他稳定性分析案例进行对比学习以加深理解。
内容概要:WiFiSupply斯普莱WFS7000XB52AX5G是一款高性能、工业级的5G全网通+双频WIFI6无线AP基站,支持5G与工业大功率Wi-Fi链路无缝切换与带宽聚合,具备高达2974Mbps的双频带宽和1000Mbps以上的实际吞吐量。设备采用MIMO 4T4R架构,支持OFDMA、AI智能FastRoaming等先进技术,实现低至20ms的漫游切换延迟和超远传输距离(点对点桥接可达150公里以上)。产品具备IP68防水、-45~85℃宽温运行、多重看门狗、防浪涌、防静电等工业级防护设计,适用于复杂恶劣环境。支持胖瘦AP模式、多种认证与管理方式(含云平台、API接口),并集成丰富的网络安全与QoS功能,适用于智慧物流、工业4.0、巡检机器人、无人机、车载船舶等多种场景。; 适合人群:从事工业物联网、智能制造、自动化物流、智能交通等领域的网络工程师、系统集成商、设备制造商及技术决策人员。; 使用场景及目标:①实现移动设备(如AGV/AMR/巡检机器人)在高速移动中的零丢包、低延迟无线漫游;②在无固定网络覆盖区域构建高带宽、高可靠的远距离无线通信链路;③为5G与工业Wi-Fi双链路备份与聚合提供一体化解决方案,保障关键业务连续性;④在复杂电磁环境下实现稳定、安全的数据传输与远程控制。; 阅读建议:本产品技术参数详尽,建议结合具体应用场景重点关注其无线性能、漫游技术、供电方式与安装选项,并参考官方提供的管理平台与API接口文档进行系统集成与远程运维规划。

1,594

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 网络通信/分布式开发
社区管理员
  • 网络通信/分布式开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧