Search The ForumSearch   RegisterRegister  LoginLogin

MailBee.NET SMTP

 AfterLogic Forum : MailBee.NET SMTP
Subject Topic: Relaying emails Post ReplyPost New Topic
Author
Message << Prev Topic | Next Topic >>
Alex Shloma
Newbie
Newbie


Joined: 22 August 2014
Online Status: Offline
Posts: 22
Posted: 22 August 2014 at 1:08am | IP Logged Quote Alex Shloma

Hi,

I want to use your SMTP component for direct relaying to the recipients. To achieve this I started to use Jobs, because I have a lot of emails. But I do not see how properly I can monitor successful/unsuccessful delivery to all recipients.
Example: email with two recipients, one is correct, another - mistake in address. In ErrorOccurred handler I can see the error reason, but do not see explicit pointing to what Job is it and delivering to what recipient got fail.
In MessageSent handler I can check collection FailedRecipients, but this event will be triggered only after sending to all recipients.

Please advice how can I immediately pinpoint what recipient has issue and what Job's ID is.

Many thanks,
Alex Shloma
Back to Top View Alex Shloma's Profile Search for other posts by Alex Shloma
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 22 August 2014 at 2:06am | IP Logged Quote Alex

You can probably use Smtp.MessageRecipientSubmitted event for that (and its Result property). Although it does not provide immediate access to the Job, it at least provides the reference to the MailMessage to which the recipient belongs.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
Alex Shloma
Newbie
Newbie


Joined: 22 August 2014
Online Status: Offline
Posts: 22
Posted: 22 August 2014 at 2:49am | IP Logged Quote Alex Shloma

Thank you for quick response.

MessageRecipientSubmitted works ok even when email address is invalid.
Let me describe what I need to create, so you will be able to guide me in right direction.

I receive emails using another component, save them to DB. After some processing I retrieve them from DB and send to the recipient. For direct relaying I am going to use your component.
Because of I have emails from different senders and to different recipients, I created one instance Smtp object and use Jobs for adding messages for delivering.
But I also need to have fail-over: repeat attempts to deliver after some timeout, control count of delivery attempts, keep records who received and who not, so even after exe will be restarted - I will be able to continue delivering to the rest of recipients.

That's why I am looking for way how can I identify what recipient received or did not receive, and save this info to DB. Example: message has 5 recipients, we started delivering. 2 received, 1 failed, 2 pending and program was killed. After restarting I need to deliver to the rest 2 recipients

Thanks,
Alex Shloma
Back to Top View Alex Shloma's Profile Search for other posts by Alex Shloma
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 22 August 2014 at 3:14am | IP Logged Quote Alex

You should use Smtp.MessageSubmittedToServer event then. It will let you track which recipients have been processed (and what the result was).

Once it's fired, you know that its IntendedRecipients have been processed (AcceptedRecipients and RefusedRecipients gives you which were lucky and which weren't). You can remember them as "processed". At the same time, if the message as many recipients on different domains, it may result in multiple MessageSubmittedToServer events for a single message. In case if you had, let's say, 6 recipients total, on two domains (3 recipients per domain), and the program was shut, you may end up with the situation that 1st domain recipients have already been processed and MessageSubmittedToServer was fired was them, while for another domain only 1 recipient was submitted and then the program was aborted (so that MessageSubmittedToServer was not fired for 2nd domain).

In this case, using MessageSubmittedToServer to track processed recipients will work well. You will need to record only 1st domain recipients because the fact than one recipient for second domain was already accepted (or rejected) by the 2nd domain's mail server actually means nothing. Before MessageSubmittedToServer was fired, no recipients are actually can be treated as "processed". SMTP tends to be a transactive protocol. If the connection gets closed before the message data is accepted by the server, all recipients accepted for this message earlier are "lost".

The only exception which makes MessageSubmittedToServer not ideal is that, unfortunately, no way to tell when the server actually says "yes". So, in some rare cases, fuzzy situation may occur: MailBee tranmitted all the data, the server accepted the message and issued "OK" but the connection broke at this point and the program was shut. MailBee won't receive that "OK" and MessageSubmittedToServer will not fire. But should be very rare situation unless the server thinks too long between receiving all the message data from MailBee and saying OK.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
Alex Shloma
Newbie
Newbie


Joined: 22 August 2014
Online Status: Offline
Posts: 22
Posted: 22 August 2014 at 4:04am | IP Logged Quote Alex Shloma

Thank you for help. Will try to play with this suggestion.
Back to Top View Alex Shloma's Profile Search for other posts by Alex Shloma
 
Alex Shloma
Newbie
Newbie


Joined: 22 August 2014
Online Status: Offline
Posts: 22
Posted: 25 August 2014 at 10:29am | IP Logged Quote Alex Shloma

Hi Alex,

How can I identify Job in MessageSubmittedToServer event? I can get e.Tag in MessageSent, but do not see how to identify task in MessageSubmittedToServer and ErrorOccurred events. I plan to use these events for saving info to DB about who received email, who did not and caused error.

Many thanks,
Alex Shloma
Back to Top View Alex Shloma's Profile Search for other posts by Alex Shloma
 
Alex
AfterLogic Support
AfterLogic Support
Avatar

Joined: 19 November 2003
Online Status: Offline
Posts: 2206
Posted: 25 August 2014 at 12:47pm | IP Logged Quote Alex

MessageSubmittedToServer (and many other SMTP events) provide MailMessage reference. You can use its .MessageID as a tag.

ErrorOccurred does not have MailMessage property anything like that as it's too general. It's not necessarily linked to any particular recipient or message or SMTP at all. But it has Reason property which references the exception occurred. And if this exception is SMTP-related, it will have MailMessage property.

Code:
IMailBeeSendException sendEx = e.Reason as IMailBeeSendException;
if (sendEx != null) {
  MailMessage msg = sendEx.MailMessage;
}


And there is Smtp.MessageRecipientSubmitted event which lets you track whether a particular recipient has been accepted or not. Perhaps it's closest to what you're about.

But. Direct send is not reliable. It all can work only to certain degree of quality. The nature of direct send makes it only a backup strategy. Relying on it as a primary source of delivery won't do any good in some ways.

Consider ErrorOccurred. You may use it to track that certain recipients failed. But what if the domain has multiple MXes assigned? After raising error event, MailBee may try another MX and still deliver the message. Thus, intermediate errors can be overridden/invalidated by subsequent actions. Only MessageSent/MessageNotSent events which occur after the entire process of sending a particular message can be reliable source of delivery results.

Also, in case if the connection to the MX host failed, ErrorOccurred won't help as it's not that the particular recipient failed. In this case there is no recipient's address to link with the exception.

Regards,
Alex
Back to Top View Alex's Profile Search for other posts by Alex
 
Alex Shloma
Newbie
Newbie


Joined: 22 August 2014
Online Status: Offline
Posts: 22
Posted: 26 August 2014 at 12:54am | IP Logged Quote Alex Shloma

Thank you.

"Relying on it as a primary source of delivery won't do any good in some ways." - correct me if I am wrong, but you do NOT recommend to use SMTP component as "message delivering engine"?

Thanks,
Alex
Back to Top View Alex Shloma's Profile Search for other posts by Alex Shloma
 

If you wish to post a reply to this topic you must first login
If you are not already registered you must first register

  Post ReplyPost New Topic
Printable version Printable version

Forum Jump

Powered by Web Wiz Forums version 7.9
Copyright ©2001-2004 Web Wiz Guide