gpt4 book ai didi

delphi - 通过XE2 delphi发送电子邮件时出错

转载 作者:行者123 更新时间:2023-12-03 15:50:20 25 4
gpt4 key购买 nike

我正在使用这个简单的代码发送电子邮件,它适用于大多数 SMTP 服务器,但适用于使用 RFC 2554 中定义的 SMTP AUTH 扩展的服务器。它显示此错误:

错误:有效的 RCPT 命令必须在 DATA 之前

这是代码:

    SMTP.Host := 'host.com';
SMTP.Port := 25;
SMTP.Username:= 'user@host.com';
SMTP.Password:= 'pass';
MailMessages.From.Address:='address@address.com';
MailMessages.From.Name:= 'Ehsan';
MailMessages.Subject := 'Test';
MailMessages.Body.Text := 'the body is going to test';
MailMessages.ReceiptRecipient.Address := 'ehsan.hesam13@gmail.com';

try
try
SMTP.Connect;
SMTP.Authenticate;
SMTP.Send(MailMessages);
except on E:Exception do
StatusMemo.Lines.Insert(0, 'ERROR: ' + E.Message);
end;
finally
if SMTP.Connected then SMTP.Disconnect;
end;
end;

如何在XE2中解决这个问题?谢谢

最佳答案

确保您填写了 TIdMessage.RecipientsTIdMessage.CCListTIdMessage.BCCList 属性。这些是 TIdSMTP 获取其 SMTP RCPT TO 命令地址的属性。您无法在未指定收件人的情况下发送电子邮件。您只需填写 TIdMessage.ReceiptRecipient 属性,该属性仅用于指定收件人将已读回执发送到的返回地址(如果收件人支持已读收件人)。

此外,您不需要手动调用Authenticate()Send() 在需要时在内部为您调用它。

关于delphi - 通过XE2 delphi发送电子邮件时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17814999/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com