If you send an e-mail to multiple recipients, it may turn out that the server has accepted some recipients while other recipients have been rejected. The SMTP protocol is very permissive in this regard, and the message will be accepted for delivery even if at least one recipient was accepted. So does MailBee.NET.
However, such «partial delivery» may not be suitable for you in case if you believe your e-mail makes sense only if delivered to all the recipients). In this case, you can tell MailBee.NET to cancel the submission of the e-mail to the SMTP relay server if any recipient gets rejected.
In case if you allow failed recipients, you can then track which recipients have succeeded and which ones have failed. You can do this both during and after sending the message. You can also make a decision whether to allow failed recipients on per-recipient basis.
Anyway, it’s important to understand that even if your SMTP relay server has accepted some recipients, this does not yet guarantee they will actually receive the message. For performance sake, your server may just accept all the e-mail addresses you’re submitting to it without making any additional checks. Also, even if the server finds the particular e-mail address to be valid, it does not yet mean that address actually exists (it only means the domain part of the address is valid).
Note that you can enable or disable failed recipients only when sending via an SMTP relay server. If you’re using direct send via DNX MX lookup, it’s not possible to disallow failed recipients. This is because direct send is not an «atomic» operation (transaction) which can be easily rolled back at any moment.
For instance, if you send to [email protected] and [email protected] via DNS MX lookup, MailBee.NET needs to create separate connections with SMTP MX servers of firstdomain.com (MX1) and seconddomain.com (MX2). If MX1 has accepted the message but MX2 hasn’t, it’s not possible to tell MX1 to «forget» the message it just received.
Of course, direct send does not permit failed recipients if you send to a single recipient only (if it fails, nobody will receive the message, so you never have the «partial delivery» problem with single recipients). Due to this and some other reasons, it’s recommended to send e-mails in «direct send» mode only to single recipients.
Allow or disallow refused (failed) recipients
By default, refused (failed, rejected) recipients are allowed. To enable that the e-mail will be sent only if all the recipients are accepted, setВ SmtpServer.AllowRefusedRecipientsВ toВ falseВ in theВ SmtpServerВ object which represents the SMTP relay server you’re connecting to:
The samples throughout this guide assume that MailBee and MailBee.SmtpMail namespaces are imported and MailBee.NET SMTP license key is set. SeeВ Import namespaces and set license keyВ topic for details.
Get successful and failed recipients after sending e-mail
Once the message has been sent, you can check which recipients have been accepted or rejected. The sample below displays failed and successful recipients in two different ways:
In case if your server always accepts all recipients regardless if they belong to existing domains or not, you can check the work of the sample by editing one or two recipients’ e-mail address to make them invalid (e.g. remove @ symbol). The server, even if it does not check the validity of domain part, should at least perform syntax check on every address.
Use events to track successful and failed recipients during sending e-mail
Events allow your application to find out which recipients have been accepted or rejected before the completion of the sending process. You may even cancel the sending if you find out that an important recipient was rejected.
The console sample below sends an e-mail to a primary recipient (listed in To) and two secondary recipients (listed in CC). Let’s assume we only care of primary recipients. If CC recipients receive the message, that’s great. If they won’t, no big deal. But we’ll cancel the sending process in case if anyone listed in To field gets rejected:
Copyright В© 2006-2017 AfterLogic Corporation. All rights reserved.