从Outlook电子邮件获取身体[Drag'n'Drop] [英] Get body from Outlook email [Drag’n’Drop]
问题描述
在这个文本框中,我想得到一个从outlook拖动的电子邮件的正文。
代码可以工作,但是我想我需要一些东西来重置ActiveExplorer,因为它只显示我拖到文本框中的最后一个新电子邮件。
示例:
拖动电子邮件1 - >文本框 - 显示电子邮件1
拖动电子邮件2 - >文本框 - 显示电子邮件2
拖动电子邮件1 - >文本框 - 显示电子邮件2和电子邮件1将不会显示,因为它已经存在于ActiveExplorer中,它将显示电子邮件2。
希望我的问题对你来说有点清楚。 。
提前感谢!
XAML代码:
code>< TextBox
Name =myTextbox
AllowDrop =True
PreviewDragEnter =email_DragEnter
PreviewDrop =email_Drop/>
XAML代码:
private void email_DragEnter(object sender,DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void email_Drop(object sender,DragEventArgs e)
{
Outlook.ApplicationClass oApp = new Outlook.ApplicationClass();
Outlook.Explorer oExplorer = oApp.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;
foreach(oSelection中的对象项)
{
Outlook.MailItem mi =(Outlook.MailItem)项;
myTextbox.Text = mi.Body.ToString();
}
}
将如下的DragDrop事件中的 oApp
的声明移动到其中,并按预期方式工作。
code> void Startup()
{
_Outlook = new Outlook.Application();
}
Outlook.Application _Outlook = null;
private void Form1_DragEnter(object sender,DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void Form1_DragDrop(object sender,DragEventArgs e)
{
richTextBox1.Text =;
Outlook.Explorer oExplorer = _Outlook.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;
foreach(oSelection中的对象项)
{
Outlook.MailItem mi =(Outlook.MailItem)项;
richTextBox1.AppendText(mi.Body.ToString()+\\\
------------------------------ ---------- \\\
);
}
}
--------编辑 - ------
OR由于此循环,您是否可以仅显示最后一个项目?
foreach(oSelection中的对象项)
{
Outlook.MailItem mi =(Outlook.MailItem)项;
myTextbox.Text = mi.Body.ToString(); //< ---仅最后的项目文本
}
I’m working with WPF and I’m trying to make a drag’n’drop textbox.
In this textbox I want to get the body of an email which I drag from outlook.
The code works but I think I need something to "reset" the ActiveExplorer cause now it only shows the last "NEW" email which I drag into the textbox.
Example:
Drag email 1 -> Textbox - Shows email 1
Drag email 2 -> Textbox - Shows email 2
Drag email 1 -> Textbox - Shows email 2 and email 1 will not be displayed because it already exists in the ActiveExplorer and it will show email 2.
Hope my question is a bit clear to you..
Thanks in advance!
XAML code:
<TextBox
Name="myTextbox"
AllowDrop="True"
PreviewDragEnter="email_DragEnter"
PreviewDrop="email_Drop" />
XAML code behind:
private void email_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void email_Drop(object sender, DragEventArgs e)
{
Outlook.ApplicationClass oApp = new Outlook.ApplicationClass();
Outlook.Explorer oExplorer = oApp.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;
foreach (object item in oSelection)
{
Outlook.MailItem mi = (Outlook.MailItem)item;
myTextbox.Text = mi.Body.ToString();
}
}
I moved the declaration of oApp
out of DragDrop event as below, and it works as expected.
void Startup()
{
_Outlook = new Outlook.Application();
}
Outlook.Application _Outlook = null;
private void Form1_DragEnter(object sender, DragEventArgs e)
{
e.Effect = DragDropEffects.Copy;
}
private void Form1_DragDrop(object sender, DragEventArgs e)
{
richTextBox1.Text = "";
Outlook.Explorer oExplorer = _Outlook.ActiveExplorer();
Outlook.Selection oSelection = oExplorer.Selection;
foreach (object item in oSelection)
{
Outlook.MailItem mi = (Outlook.MailItem)item;
richTextBox1.AppendText(mi.Body.ToString() + "\n----------------------------------------\n");
}
}
--------EDIT--------
OR Is it possible that you display only the last item because of this loop?
foreach (object item in oSelection)
{
Outlook.MailItem mi = (Outlook.MailItem)item;
myTextbox.Text = mi.Body.ToString(); //<--- Only last items text
}
这篇关于从Outlook电子邮件获取身体[Drag'n'Drop]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!