[Outlook 07-13] Help with subject changed needed

Add-in Express™ Support Service
That's what is more important than anything else

[Outlook 07-13] Help with subject changed needed
 
Christian Fasold




Posts: 45
Joined: 2013-11-27
Hello everybody,

I have a strange bug which doesn't always happen, but sometimes.
I have now spent two days trying to get to the bottom of the problem, but I am out of ideas now :-(

What am I doing?

I have created a Ribbon where you can save mails as templates and load them again.
Now if you try to overwrite an already existing template (those are normal mails stored in a sub-folder in the Inbox), my addin deletes the old template mail from the folder and saves the currently active inspector/eMail window as a new template.
That works perfectly for all parts of the template (recipient(s), attachment(s), body) but NOT for the subject line :-(
Sometimes the wrong subject line gets saved...
What is the exact workflow?
- Create a new empty mail
- Use the ribbon to load an existing template
(-> recipient(s), attachment(s), subject line and body are copied from the template into the new empty mail)
- Change the subject line
- Select "Save template" and chose the exact same name as an already existing template
(-> the system checks and finds out that there is already a template existing with that name, so it deletes
the old template and then does the same as if you would save a completely new template:
- Create a new empty mail (in the background) and copy the recipient(s), attachment(s), subject line and body into it
- Save it as a new template in the sub-folder of the inbox)
And HERE happens the problem: everything is copied perfectly fine from the current edit-window into the new template
mail BUT the subject line. That only works ~ 60% of the time.

The question is: why is that always only happening when I "overwrite" an old template? Because basically "overwriting" is exactly the same as a new save but with deleting the old template first.

Another very interesting (but disturbing) thing I have noticed:
When I debug into the statement for copying the subject line:

newTemplateMailItem.Subject = mailItem.Subject  ' Copy subject

and the bug just happens, then I see in the beginning in the watch-context menu of "mailItem" (which is the currently open mail window) still the OLD value of the subject line! In the Outlook edit window I can see the newly typed subject line. When I now scroll down in the watch-context-menu of VS 2013, suddenly the contents change and I see the correct subject line in there. That is something I completely don't understand, as if there was a "refresh" after some time of the mailItem contents (mostly the subject line).

Can you hopefully help me in ANY way as I have absolutely no clue anymore how to fix that :-/

As mentioned before, ALL other fields (body, recipient(s), attachment(s)) work perfectly fine, it is just the (simple?) subject line...

Thanks a lot and best regards,

Christian
Posted 24 Mar, 2015 08:59:49 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Hello Christian,

You need to save the MailItem before you copy MailItem.Subject. Actually, you could get this issue with a recipient entered manually.


Andrei Smolin
Add-in Express Team Leader
Posted 24 Mar, 2015 09:49:13 Top
Christian Fasold




Posts: 45
Joined: 2013-11-27
Hello Andrei,

once again you are the life saver ;-)
I wouldn't have guessed that I had to save the mail before copying the contents as it always worked perfectly (besides sometimes the subject line)...
Now it _seems_ to work really great, thank you!

May I ask one more question:
How would I find out if the currently open mail window opened by the user double clicking on an already sent mail?
What I would like to achieve is this:
I need to do different things with the open mail depending if it is a newly opened mail (Click on "New Mail") or if it is a re-opened, already sent mail...
Can I check for the existance of the "Send"-Button (which is not there when a sent mail is re-opened)?

Thanks a lot for your help!

Best regards,

Christian
Posted 25 Mar, 2015 04:21:59 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Hello, Christian!

You are welcome. An email being composed and a received/sent email have different values of the MailItem.Sent property; the property returns True for a received/sent email.


Andrei Smolin
Add-in Express Team Leader
Posted 25 Mar, 2015 05:53:13 Top
Christian Fasold




Posts: 45
Joined: 2013-11-27
Andrei,

again THANKS :)

That seems to have worked perfectly :)

Best regards,

Christian
Posted 25 Mar, 2015 08:12:29 Top
Andrei Smolin


Add-in Express team


Posts: 18817
Joined: 2006-05-11
Welcome! ))


Andrei Smolin
Add-in Express Team Leader
Posted 25 Mar, 2015 08:49:47 Top