Exchange Web Services - sending email error "item is out of date" - exchange-server

I have code which sends email via EWS (it has to read incoming email and move messages, so sending via EWS instead of SMTP makes some sense). 95% of the time it works, but occasionally I get an error saying:
"The operation can't be performed because the item is out of date. Reload the item and try again."
I already am saving the email in the Sent Items folder and then calling Bind() to reload the message before trying to send. Any insights into what is going on and why? Also, how to avoid or recover since Bind() isn't reloading the message?

I already am saving the email in the Sent Items folder and then calling Bind() to reload the message before trying to send
Why are you saving it to the Sentitems folder before sending? its better to use drafts folder as a number of different things maybe syncing against the other folders (including the substrate processes in Office365). It sounds like the changekey is out of date probably because another process has made a changed to the Sent Message.

Related

Polling Outlook mail folder (inbox) occasionally returns ErrorInvalidMailboxItemId

Something strange occurs that I cannot find the cause or reason for.
I have a loop which polls Inbox for an authorized user every minute. This goes fine for some time, but then I get 404 and error code is ErrorInvalidMailboxItemId (Item Id doesn't belong to the current mailbox.). I for example get this two times and then the polls starts working again.
GET /v1.0/me/mailFolders/xxx/messages?$filter=isRead%20ne%20true&$count=true&$top=10
Nothing that I can see is different between the polls, so I'm baffled why server suddenly returns 404.
Searching for this error mentions shared mailbox, archive and delegated, however this inbox is neither of these, and besides the error should then be consistent which it is not.
Same bearer token used for all the polls, both when it works, then does not and then when it starts working again.
Any ideas why this goes wrong? Or do I have to look for this error and then just retry or ignore the error for some time?
Thanks
I would try the following:
Do a re-try and see if it works
Implement the detailed response logging at the custom application end, isolate the item, make the same API call in MS Graph Explorer and see if it exists, gets the data or not.
Make sure you have necessary permissions to access the shared mailbox, archive mailboxes or the targeted mailboxes etc

How to improve email robustness? [mailgun, laravel]

I planned to improve email robustness using below way. I am using laravel and mailgun. If any bounces email is in the mailgun then i want to send that to someone related to the email(not to that previous receiver and it related with previous sender or someone) so that i plan to use Task scheduler and schedule every hour this process. After that email send successfully i want to remove that email from mailgun.
I actually want to know how to implement get bounces email from mailgun and if send successfully using Task scheduler i want to remove that email from mailgun. if any sample's to achieve this? or any different ideas?
Normally when a bounce happens, providers such as Mailgun will retry a few times depending on the bounce status/type. After failing to send to that email address, Mailgun will put that address into your Bounces list to avoid sending to that address in the future. There's really no point in trying to send emails to an address which doesn't exist, inbox is full, domain expired, etc. So perhaps you should review your bounce list before you consider doing this. Mailgun's dashboard provides the description and date it happened. If you wish to send to a particular address again, you can remove the address from the bounce list. More about bounces here.
You can use mailgun-php or simply use Guzzle to call their API to retrieve your bounces. I'm not sure what you meant my removing email, but hope this helps.
Edit:
You can use their API to get all your bounces, and also the message content (retention depends on your plan or settings) if you need the original content. You could also use their webhooks to get the failed emails, so you don't really need to schedule/cron.
Edit 2:
The bounce list only stores email addresses of previously bounced emails. Also, I just realized that, if you're checking hourly for bounced messages, looks like the suppression/bounce API won't be of much help since you can't know if a message has failed for an address already on the list. This is the only data from bounce list:
{
"address": "alice#example.com",
"code": "550",
"error": "No such mailbox",
"created_at": "Fri, 21 Oct 2011 11:02:55 GMT"
},
So looks like you've to use the events API or webhooks to get the failed messages.
I've used mailgun-php sometime ago, and I found that the it wasn't easy working with Events on that library due to protected properties of the class. So if you have trouble, maybe just use Guzzle or use webhook approach instead.

Dynamics 365 online issue with Email Synchronization (SSS)

in my organization we have a mailbox that receives email from different sources (about 5) everyday, set to track all incoming emails in the CRM.
All the mails are correctly tracked on the CRM every day, except for one that always fails (same source, similar content every day).
If I send the exact same email from another address, the mail is correctly synchronized with the CRM, so I think it could be something related with Exchange.
This is the message I get if I open the mailbox record:
An unknown error occurred while receiving email through the mailbox "xxxxxx".
The owner of the associated email server profile xxxxx has been notified. The system will try to receive email again later.
Email Server Error Code: Exchange server returned UnknownIncomingEmailIntegrationError -2147220970 exception
Looking for this specific message didn't get me any result, while just searching the error code I found out it could be something related to plugins.
Unfortunately there is no plugin that fires on email creation, same for workflows and so on. By the way, sending the email from another address just works fine.
Has anyone ever had such a problem? Is there some place where I can find other logs and dig deeper in the problem?
Thanks in advance.
For anyone else experiencing this issue: I received the error code -2147218683, which is different, but it turns out this was due to the user in question not having the right security role. Gave the account sys admin and the error went away.

Check Directory for files after FTP operation

I currently have two custom business operation scripts that detect whether a file or files have been ftped. If the job was successful an email is sent.
I am looking to check if the directory is empty and if so send an email letting the user know that no files were found.
I am thinking that it would be done on the inbound service but can't quite figure out the code.
If you just want to send a notification (email) for an empty directory (through ftp), you can do it without any code from an inbound service by setting the Alerting Control parameters :
Alert on Error ( AlertOnError ) = true
Inactivity Timeout ( InactivityTimeout ) = number of seconds before raising the alert
NB: additionally, if not already existing, you'll need to add the Ens.Alert component, generally a simple business process router (ie: EnsLib.MsgRouter.RoutingEngine) which will receive the Alert Message and route it to the appropriate business operation in charge of sending the alert via email (ie: EnsLib.EMail.AlertOperation or a similar email operation).

run a script or sanity check against outgoing emails in outlook 2010

Is there a way to setup Outlook 2010 to run a script or some other form of sanity-check when you attempt to SEND messages from the client? My specific situation is that I use the same outlook client for multiple accounts (work, gmail, VPS server, etc) and I've found myself a couple of times sending emails "from" the wrong account.
In a perfect world I'd want to be able to write a script with logic something like the following:
when (I hit send)
if (the "source" account is "myuserid#gmail.com") then
if (there are addresses in TO or CC that match "work.com") then
pop up a dialog box that says:
"You appear to be sending email to work.com from gmail.com - do you really want to do this?"
if yes, then send it and return
if no, go back to the message compose window
that way, I'd have to actually very intentionally use a non-work email address to send email to the work people (which is rare in my particular case)
Try SendUsingAccount to read the "source" account in ItemSend.

Resources