Question

I'm using Indy and Delphi to send email messages. I've had no issues until one of the users was recently let go. Their email account was deleted and my program attempted to email about seven users including the "downsized" user. I expected the SMTP server to accept the email and deliver the message to the valid users and then send an email back to the Sender informing them that the one account in the recipients list is no longer valid.

Instead the SMTP server did not accept anything and no one received the message. I got "Mailbox Unavailable" in my log. Is there a setting to change this behavior on my end? Email clients like Outlook certainly do not behave this way.

Specifically, what is the proper technique to send messages so that all valid email addresses in the recipients lists get delivery, and the Sender is notified by the SMTP server of any incorrect addresses?

Thanks in advance.

Était-ce utile?

La solution

If you are using Indy 10 then you need to assign a handler to the TIdSMTP.OnFailedRecipient event and have it set the VContinue parameter to True.

procedure TForm1.IdSMTP1FailedRecipient(Sender: TObject; const AAddress, ACode,
  AText: string; var VContinue: Boolean);
begin
  // do something...
  VContinue := True;
end;

That will allow TIdSMTP to skip the failed recipient and keep sending the email to the remaining recipients. Only if all of the recipients fail will TIdSMTP then fail the send (unless some other non-recipient error occurs, of course).

If you are using Indy 9 or earlier, or do not provide an OnFailedRecipient handler, TIdSMTP will fail and abort the send on the first error encountered, including a recipient error.

The SMTP server will NOT send a notification to the sender's inbox if it actively rejects a given recipient while the email message was still in process of being given to the server by the sender. You will have to use the OnFailedRecipient event to act upon that recipient. Only recipients that are accepted by the server and then later found to be in error will then send a notification to the sender's inbox accordingly. That is simply how SMTP works.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top