Need another view becouse im lost.
In outlook there are two ways to send an email, a new window for New Email or from a Message preview. I need a function that checks both sending options so that the user does not forget to attach the attachment.
I found this fantastic code here https://stackoverflow.com/a/54084998/3681759
The problem is that the function always says that no attachment is attached.
private void Btn_Check_Click(object sender, EventArgs e)
{
Microsoft.Office.Interop.Outlook.Application application = new Microsoft.Office.Interop.Outlook.Application();
Inspector inspector = application.ActiveInspector();
if (application.ActiveExplorer().Selection[1] is MailItem explorerMailItem)
{
if (explorerMailItem.Attachments.Count == 0)
{
MessageBox.Show("Attachments isnt here");
this.Hide();
}
else
{
AddItemsForm f2 = new AddItemsForm();
f2.ShowDialog();
this.Hide();
}
} else if (inspector.CurrentItem is MailItem inspectorMailItem)
{
if (inspectorMailItem.Attachments.Count == 0)
{
MessageBox.Show("Attachment isnt here");
this.Hide();
} else {
AddItemsForm f2 = new AddItemsForm();
f2.ShowDialog();
this.Hide();
}
}
}
Firstly, use Application.ActiveWindow
and cast it as Inspector
or Explorer
to see which window is actually active.
Secondly, in case of Explorer
, do not use Explorer.Selection
, use Explorer.ActiveInlineResponse
(returns null or the new item being composed inline).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.