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什么的,请高手指教!!
...全文
422 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”试试
内容概要:本文围绕“粒子群优化算法驱动的永磁同步电机电流环多参数协同辨识研究”,提出一种基于Simulink仿真实现的高精度参数辨识方法,旨在解决永磁同步电机(PMSM)在高性能电流控制中因关键参数(如电感、电阻、永磁磁链等)不准确或时变所导致的控制性能下降问题。研究构建了PMSM的精确数学模型,并在Simulink环境中搭建完整的电流环控制系统仿真平台,创新性地引入粒子群优化算法(PSO)对多个关键参数进行在线或多工况下的协同辨识。文中详细阐述了PSO算法的核心机制、适应度函数的设计原则(通常基于模型输出与实际响应的误差最小化)、参数初始化与收敛判据,并通过大量仿真实验验证了该方法在不同负载和运行条件下的辨识精度、收敛速度与强鲁棒性,有效提升了电流环的动态响应能力、抗干扰性和整体控制系统的稳定性。; 适合人群:具备电机控制理论、现代智能优化算法基础及MATLAB/Simulink仿真能力,从事电气工程、自动化控制、新能源汽车电驱动系统等领域的高校研究生、科研人员及企业研发工程师。; 使用场景及目标:①应用于高精度伺服驱动、电动汽车电驱系统等对电机参数敏感的高端装备中,实现控制器的精细化标定与自适应;②为智能优化算法在复杂非线性系统参数辨识领域的工程应用提供完整的仿真案例和技术范本;③服务于电机控制系统的故障诊断、性能评估及下一代自整定控制器的研发。; 阅读建议:建议读者结合提供的Simulink模型与MATLAB代码进行动手实践,重点剖析PSO算法与电机模型的耦合机制,深入理解适应度函数的构建逻辑,并可进一步尝试将该方法拓展至温度补偿、磁饱和等非线性因素的联合辨识,或迁移至其他类型的电机(如感应电机)控制中,以深化对数据驱动与模型驱动融合控制策略的理解。

1,594

社区成员

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

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