我有一个功能区按钮,我想将邮件正文、主题和发件人电子邮件地址存储到三个单独的字符串变量中。到目前为止我一直在处理的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Office.Tools.Ribbon;
using Outlook=Microsoft.Office.Interop.Outlook;
using office = Microsoft.Office.Core;
using System.IO;
namespace OutlookAddIn1
{
public partial class Ribbon2
{
string s1,s2,s3;
private void Ribbon2_Load(object sender, RibbonUIEventArgs e)
{
}
void extract(string s1, string s2, string s3)
{
string Body,address,subject;
Outlook._Application oApp = new Outlook.Application();
if (oApp.ActiveExplorer().Selection.Count > 0)
{
Object selObject = oApp.ActiveExplorer().Selection[1];
if (selObject is Outlook.MailItem)
{
Outlook.MailItem mailItem = (selObject as Outlook.MailItem);
subject = mailItem.Subject;
address = mailItem.SenderEmailAddress;
Body = mailItem.Body;
s1 = Body;
s2 = address;
s3 = subject;
}
}
}
private void button1_Click(object sender, RibbonControlEventArgs e)
{
extract(s1,s2,s3);
System.Windows.Forms.MessageBox.Show(s1);
System.Windows.Forms.MessageBox.Show(s2);
System.Windows.Forms.MessageBox.Show(s3);
}
}
}
但是消息框显示为空。