0

In Outlook Web Add-In, I'm trying to intercept OnSend event which is triggered when sending an email.

I used this example in GitHub which is working fine.

If I include the word "attachment" in the email body and I click Send button, OnSend event is fired for the first time so I can do some processing to email's content. However, after a while, a pop-up modal window shows up with this message:

Attachment reminder

You may have forgotten to attach a file.

with Send and Don't send buttons. If click Send, OnSend event gets fired a second time. This time, It would be useless to repeat the same email processing. So, I'm looking for a way to find out that the second OnSend event is fired after an Attachment reminder.

Is there a way to distinguish between first and second OnSend events?

Mhd
  • 2,778
  • 5
  • 22
  • 59

1 Answers1

0

Thanks for your question, Mhd! This appears to be unintentional behavior, essentially a defect that we will look into fixing. ItemSend event should inter operate with forgotten attachment detection nicely, and should only be raised after the detection happened. In other words, the first event should not be called at all. Is it a problem if you do the processing twice until this issue is resolved?

  • Unfortunately It is a problematic for me as I'm adding more content to email body when `OnSend` event is fired. So It will be added twice. Since you confirmed the issue, I will try to remember sent items (use local storage) to avoid duplicate processing. Also I noticed that `OnSend` event is fired two times after clicking **Send** button within attachment reminder window (without counting the first event before attachment reminder) https://stackoverflow.com/questions/45489188/onsend-fired-twice-after-attachment-reminder/45489927?noredirect=1#comment77976834_45489927 – Mhd Aug 15 '17 at 18:02
  • Got it. Yeah then indeed you need to come up with a workaround. One you are thinking about might work. You could also try setting a custom property on the item indicating that it's been processed already, and when event is raised again, check the property first and if set ignore the event. I am not aware of your scenario though - what happens if a user cancels the send in the attachment dialog and modifies the message content - would you need to re-process the message or not? – Outlook Add-ins Team - MSFT Aug 15 '17 at 23:00
  • I like the idea of custom property better than local storage. Thanks!!! If the email body has been modified, I have to re-do the processing and insert new content based on the new email body. But I have to ignore the first process (remove first inserted content) though. How can I handle this scenario? – Mhd Aug 16 '17 at 03:02
  • You could wrap it into a div with certain ID so it's easy to find/remove? For plain text email case (if you support it at all), you'd need to handle that separately - maybe use some keywords in the beginning/end instead to identify the content you're adding? – Outlook Add-ins Team - MSFT Aug 18 '17 at 02:07
  • Using keywords will not work perfectly in different languages. However, I'm thinking about saving original body and catching **Don't send** button click event, so I can replace modified body with original one. Is it possible to get "Don't send" event? – Mhd Aug 18 '17 at 16:45
  • No there is no such capability, and I doubt we'd add anything like that in near future. We'd rather fix the bug instead, which should solve your problem! – Outlook Add-ins Team - MSFT Aug 18 '17 at 22:56