Reputation: 146
I am using this simple code to send emails it works for most SMTP servers but for the Servers which using SMTP AUTH extension as defined in RFC 2554. it shows this error:
ERROR: valid RCPT command must precede DATA
here is the code :
SMTP.Host := 'host.com';
SMTP.Port := 25;
SMTP.Username:= '[email protected]';
SMTP.Password:= 'pass';
MailMessages.From.Address:='[email protected]';
MailMessages.From.Name:= 'Ehsan';
MailMessages.Subject := 'Test';
MailMessages.Body.Text := 'the body is going to test';
MailMessages.ReceiptRecipient.Address := '[email protected]';
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;
how can i solve this problem in XE2? thankx
Upvotes: 3
Views: 2842
Reputation: 146
Thank you all , I have filled the Recipients.EMailAddresses
and it worked :D
here is the correct code :
SMTP.Host := 'host.com';
SMTP.Port := 25;
SMTP.Username:= '[email protected]';
SMTP.Password:= 'pass';
MailMessages.From.Address:='[email protected]';
MailMessages.From.Name:= 'Ehsan';
MailMessages.Subject := 'Test';
MailMessages.Body.Text := 'the body is going to test';
MailMessages.Recipients.EMailAddresses:='[email protected]';
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;
Thank you again.
Upvotes: 1
Reputation: 596352
Make sure you are filling in the TIdMessage.Recipients
, TIdMessage.CCList
, or TIdMessage.BCCList
properties. Those are the properties where TIdSMTP
gets the addresses for its SMTP RCPT TO
commands. You cannot send an email without specify the recipient(s) for it. You are only filling in the TIdMessage.ReceiptRecipient
property, which is only meant for specifying the return address that recipients send read receipts to, if recipients support read recipients.
Also, you do not need to call Authenticate()
manually. Send()
calls it internally for you when needed.
Upvotes: 4