is it possible capture sending email status outlook add-in c# - c#

I have ApplicationEvents_11_ItemSendEventHandler email sending event, but this event in email sending status is always false, so any event capture email sending is true or false.

Do you mean MailItem.Sent is still false? This is to be expected. The very first time you can access the sent message is when Items.ItemAdd event fires on the Sent Items folder. By then Sent property will be true and all the sender related properties will be populated.

Related

C# Outlook Remove event when email sent successfully?

I have a plugin outlook, I create an event when an email sent successfully, this code:
private Outlook.Items _items;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
Outlook.Application application = this.Application;
_items = Application.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderSentMail).Items;
_items.ItemAdd += new Outlook.ItemsEvents_ItemAddEventHandler(Items_ItemAdd);
}
Then, I have the user setting, and if the user doesn't select, I want to remove that event (Items_ItemAdd).
So should I do?
Well, tracking the Sent Items folder is not really a good idea. Outlook allows to remove a sent item by skipping the Sent Items folder. The DeleteAfterSubmit property of Outlook items is a Boolean value that is True if a copy of the mail message is not saved upon being sent, and False if a copy is saved in Sent Items folder. So, you will never get the event fired if users or other software like VBA macros or add-ins set this property before sending emails.
A better way is to handle the ItemSend event of the Application which is fired when a new item is received in the Inbox.
This event fires once for every received item that is processed by Microsoft Outlook. The item can be one of several different item types, for example, MailItem , MeetingItem , or SharingItem. The EntryIDsCollection string contains the Entry ID that corresponds to that item. Note that this behavior has changed from earlier versions of the event when the EntryIDCollection contained a list of comma-delimited Entry IDs of all the items received in the Inbox since the last time the event was fired.
The NewMailEx event fires when a new message arrives in the Inbox and before client rule processing occurs. You can use the Entry ID returned in the EntryIDCollection array to call the NameSpace.GetItemFromID method and process the item. Use this method with caution to minimize the impact on Outlook performance. However, depending on the setup on the client computer, after a new message arrives in the Inbox, processes like spam filtering and client rules that move the new message from the Inbox to another folder can occur asynchronously. You should not assume that after these events fire, you will always get a one-item increase in the number of items in the Inbox.
In the NewMailEx event handler you may ask users whether to process emails after sending and, if it is not, you can simply set the DeleteAfterSubmit property to true.

mailItem.PropertyChange stops firing

I am implementing Custom Task Panes with E-Mail Messages in Outlook.
The core is taken from this link MSDN (Walkthrough: Displaying Custom Task Panes with E-Mail Messages in Outlook)
Handler for property change is added:
void TaskPane_VisibleChanged(object sender, EventArgs e)
{
Globals.Ribbons[inspector].ManageTaskPaneRibbon
.toggleButton1.Checked = taskPane.Visible;
...some code here...
mailItem.PropertyChange += PropertyChangeHandler;
}
PropertyChangeHandler checks is recipients have changed and does some heavy routine with posts and so on. But... If I add 10 recipients and start to remove them with backspace PropertyChangeHandler stops firing at some point.
No errors. Buttons on custom task pane work fine.
What is wrong?
Seems that either event is eaten or inspector is incorrect, but I cannot spot problem and find the solution.
I also think that it might be about "heavy load" when next event is fired before previous is completed, but this is a guess
You need to call the Save method or save the message explicitly to make the PropertyChange event fired. Outlook caches values in the UI and doesn't propagate changes until the item is saved.
Also I'd suggest creating a log file (a regular text file) where you can write the debug statements. Thus, you will understand what happens in the code.

Keep a form opened waiting for asynchronous method response

I have a question regarding a somewhat simple problem, but I think with many solutions and I don't know what would be the best.
I have the following scenario including:
ApplicationForm
Proxy (Client -> Server side)
Possible error message dialog.
The form sends a request to do something on the server side and the form closes (this is the current implementation). I changed this so the method that is being called on the proxy, server side returns a string value that contains an error message if something fails.
The problem is that I want to display a message box when the response comes back if the message is not String.Empty
I do the following:
Call method and assign value returned to a property field.
Create a timer that has an event that fires after 4 seconds.
... Meanwhile the form closes...
Timer event fires, Check the property for a possible error in the string and fire another event that calls a method on the form and displays a message box.
The thing is, I would like to keep the form opened and after the user clicks OK on the message dialog box the form should close.
Any idea is good.

What is the right method of validating .NET Windows Forms?

I'm searching on everywhere but just couldn't find a good example or text about this subject.
I would like to check for example the username and password validity when a user presses the OK button in a dialog.
Should I do this in the closing event, and cancel the dialog close if the validation fails? Or set the DialogResult to none instead of OK. These all seem kinda the wrong way to do it. I also saw the Validated and Validating events but aren't those for only validating a single control for valid input?
How can I check more controls together when the OK button is pressed, and cancel the form closing?
It depends on what you are trying to do. If you want to verify that the user entered something that could possibly be a valid username/password, you could use the Validating events (e.g. make sure it is long enough, etc). If you want to verify that the username/password corresponds to a valid account, then you have to wait until they hit the OK button and check the credentials. If they are bad then you can throw up a message box (or whatever) and prevent the dialog from closing (DialogResult.None).
Each control offers Validating event. In this event you can implement validation of a single control. By default this validation is triggered when control lose focus. In contrast to Validated event, handler of this event receives CancelEventArgs so if validation fails you can cancel current operation (losing focus).
When you want to deal with complex validations you can set AutoValidate property of your form to AutoValidate.Disable. This will disable implicit validation (default behavior described before). Instead you will have to call ValidateChildren to trigger explicit validation of all child controls.

How to make CustomValidators fire at the same time as RequiredFieldValidators

I have a form containing both CustomValidators and RequiredFieldValidators.
The Custom Validation doesn't fire until all of the requiredFieldValidators have passed.
Can someone tell me how to get them to validate at the same time? I want all the validation messages to show when no data is input.
you need to create a javascript function and hook up the customvalidators via OnClientValidate, so that it will fire client side with the requiredfieldvalidators.
Check out: http://msdn.microsoft.com/en-us/library/f5db6z8k(VS.71).aspx

Categories