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什么的,请高手指教!!
...全文
145 8 点赞 打赏 收藏 举报
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
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”试试
  • 打赏
  • 举报
回复
相关推荐
发帖
网络通信/分布式开发
加入

1579

社区成员

Delphi 网络通信/分布式开发
申请成为版主
帖子事件
创建了帖子
2004-05-07 04:34
社区公告
暂无公告