Problem with sending multiple mails on OrderConfirm

Hello!

I’m trying to send multiple mails when an order is in the confirm state in the OrderStateBuilder class. It’s acting very unpredictable however, sometimes sending both mails at once, then with a 10 min delay on the other mail, and sometimes failing to send both. It’s not throwing any exceptions either.
My guess is that it has to do with the MailServiceProcessor Process Task being used.

Right now I’m basically just using this code snippet, with the only difference being I change the email address to the second email address which I fetch from a field of the website template.
I have a nullcheck in place and log the new email to make sure it’s not null.
IoC.Resolve().SendEmail(new OrderConfirmationEmail(orderCarrier.ChannelID, orderCarrier.ID, orderCarrier.CustomerInfo.Address.Email), true);

Do you have any solution to how I should accomplish this properly or insight into why it’s not working?

Thanks!

Litium version: [7.2]

Hard to guess, but in general I would say it is more likely that the issue is with the mailservers sender or receiver then the code. Have you checked so that you have setup SPF-records for your mail server in your dns?
Another common cause of this is spamfilters or other services that scan email and the issue is often bigger if you havent configured SPF-records for your mail server.

.

As Jonas points out it is hard to guess what happen. Do you know if the mail have been delivered to the mail server that is configured as the outgoing mail-server for your application? If the mail have been received to that mail server it is out of the control of the code how fast that the mail can be delivered.

It exists many different techniques to prevent spam, one of them is greylisting that some receiving mailserver is using. In short that process tells the sending mail server to try again for the first delivery attempt and accept the mail for the second delivery attempt. This will make the delivery speed very unpredictable.

We’re running on a local solution that just stores the emails being sent out which doesn’t require or have either SPF-records or spam filters.

I’ve been running wild with loggers all day now and from what I can tell the scheduler doesn’t always get called. It looks like this:
_schedulerService.ScheduleJob(x => x.Process(messageInfo));

I went so far as to only having a logger that logged “nonsense” in the Process method and still it only got hit once every now and then.

It does create another thread which allows the other email to start the process of being sent, and it always reaches the point before going into the MailServiceProcessor’s Process method, but then fails to call it.

I hope this gives some insight or ideas to what might be the problem!

Thanks for the replies either way :slight_smile:

  • SPF are configured on DNS level to tell what servers are valid to send mails from your domain name, without this it is higher risk that your email will be stopped in the spam filters.
  • Spam filters are configured at the receiving end for filter out mails that can be treated as unwanted.

Non of them are anything that you build in your code to send mail.

Are you the only developer that using the same database? and do you use service bus?

I’m currently the only one using the database.

I wasn’t using service bus, no, and lo and behold it seems to fix the problem!
I replaced the Scheduler with the service bus, and made the process syncronous. Works very well, just have to undergo some live testing to make sure it works properly.

Thank you for your time, much appriciated :slight_smile:

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.