我有一个文件夹,其中包含许多电子邮件和子文件夹.在这些子文件夹中有更多电子邮件.
我想写一些VBA,它将遍历某个文件夹中的所有电子邮件,包括任何子文件夹中的电子邮件.我们的想法是从每封电子邮件中提取SenderEmailAddress和SenderName使用它.
我尝试将文件夹导出为仅包含这两个字段的CSV,虽然这有效,但它不支持导出子文件夹中保存的电子邮件.因此需要编写一些VBA.
在我重新发明轮子之前,是否有人有任何代码片段或链接到网站,给定文件夹名称,显示如何获取MailItem该文件夹和后续子文件夹中的每个电子邮件的对象?
我已经尝试使用mailItem.SenderEmailAddress和mailItem.Sender.Address,但他们都返回一个字符串,它看起来像这样:
/O=DOMAINNAME/OU=EXCHANGE ADMINISTRATIVE GROUP (FYDIBOHI43SPCLT)/CN=RECIPIENTS/CN=JOE BLOGGS8C3
实际上我想要joebloggs@domainname.co.uk重新开始.
有人有主意吗?
非常感谢你.
编辑:我做了一些挖掘; 它适用于"SenderEmailType"SMTP的电子邮件地址,它只适用于Exchange电子邮件地址.
编辑2:我已经尝试了这里指定的代码,但我认为它已经过时了,因为它抛出了"无法创建Active-X组件"错误.
编辑3: 对于任何遇到与我相同问题的人,我找到了答案(在C#中,转换为VB.NET,但仍然有效):
Private Function GetSenderSMTPAddress(mail As Outlook.MailItem) As String
Dim PR_SMTP_ADDRESS As String = "http://schemas.microsoft.com/mapi/proptag/0x39FE001E"
If mail Is Nothing Then
Throw New ArgumentNullException()
End If
If mail.SenderEmailType = "EX" Then
Dim sender As Outlook.AddressEntry = mail.Sender
If sender IsNot Nothing Then
'Now we have an AddressEntry representing the Sender
If sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeUserAddressEntry OrElse sender.AddressEntryUserType = Outlook.OlAddressEntryUserType.olExchangeRemoteUserAddressEntry Then
'Use the …Run Code Online (Sandbox Code Playgroud) 我在C#中编写VSTO Outlook插件,我需要区分,无论是MailItem是传入还是传出(或者两者都不是,例如它是草稿).
有一些万无一失的方法吗?我现在的最佳解决方案是获取收件人,cc和bcc的列表,从活动帐户加载电子邮件地址,并检查这两个列表是否相交,但这对我来说似乎非常脆弱,我希望有更好的解决方案.
使用案例:我想获得一封电子邮件的相关日期,可能是ReceivedTime或SentOn,但要知道我应该使用哪一个,我想知道邮件是发送还是收到.
谢谢你的想法:)
我在Outlook的Visual Basic(我们使用的是Outlook 2003和Exchange Server)中编写了一个消息处理函数来帮助我整理收到的电子邮件.
它对我有用,除非有时规则失败并且Outlook停用它.
然后我重新打开规则并在我的收件箱中手动运行以赶上.该规则自发地失败并且每天停用几次.
我想一劳永逸地解决这个问题.
注意:我正在使用VBA和Office 2007.(我会使用C#,但项目参数不允许这样做)
我试图在Outlook或API中找到一些方法,允许我通过从Access数据库提供Outlook EntryID或MAPI"PR_ENTRYID"属性来打开Outlook邮件项.我找到了许多对所述代码的引用,但我从未见过有人真正发布过一个解决方案.我试图包括对mapi32.dll和OLMAPI32.dll的引用,但是我收到以下错误:"无法添加对指定文件的引用." 我猜这是因为那些dll是用于.NET的.
您将给予的任何帮助将不胜感激.
我已经搜索了这个看似简单的任务的高低,但我遇到的所有引用都是保存到硬盘驱动器或从outlook文件夹中读取.
我有以下代码循环我的硬盘驱动器上的文件夹中的文件名,但我不知道如何采取该路径并使用Outlook打开它.
Dim inPath as String
Dim thisFile as String
Dim msg as MailItem
Dim OlApp as Object
Set OlApp = CreateObject("Outlook.Application")
inPath = "C:\temp"
thisFile = Dir(inPath & "\*.msg")
Do While thisFile <> ""
'At this point, thisFile contains the path of a .msg like "C:\temp\mail_item1.msg"
'msg = <open mailitem> <~~~~ HELP HERE
'Do stuff with msg
thisFile = Dir
Loop
Run Code Online (Sandbox Code Playgroud)
这个问题看起来很相似,但适用于C#,所以我在获取与我的问题相关的vba等效时遇到了一些麻烦.对于更熟悉outlook vba的人来说,这可能是显而易见的.
我只是无法释放我的Outlook MailItems.打开200 Mails后,Exchange Sever返回达到的最大打开电子邮件数.
我将从所有选定的邮件中删除我的UserProperty.
我的代码:
foreach (var selection in Globals.ThisAddIn.Application.ActiveExplorer().Selection)
{
if (selection is MailItem)
{
MailItem mi = (MailItem)selection;
UserProperty up = mi.UserProperties.Find("MyProp");
if (up != null)
{
up.Delete();
//##################################
// I also tried :
//----------------------------------
// Marshal.ReleaseComObject(up);
// up = null;
//----------------------------------
}
mi.Save();
//##################################
// I also tried :
//----------------------------------
// mi.Close(OlInspectorClose.olDiscard);
//----------------------------------
// I don't know if this loop is necessary, but I have found it somewhere on the web
while (Marshal.ReleaseComObject(mi) > 0);
mi = …Run Code Online (Sandbox Code Playgroud) 嗨,我必须使用C#在Outlook 2010的本地目录中分别阅读附件和内联图像.我已经使用了属性和内容ID概念.我正在使用以下代码,但它现在正在工作.
if (mailItem.Attachments.Count > 0)
{
/*for (int i = 1; i <= mailItem.Attachments.Count; i++)
{
string filePath = Path.Combine(destinationDirectory, mailItem.Attachments[i].FileName);
mailItem.Attachments[i].SaveAsFile(filePath);
AttachmentDetails.Add(filePath);
}*/
foreach (Outlook.Attachment atmt in mailItem.Attachments)
{
MessageBox.Show("inside for each loop" );
prop = atmt.PropertyAccessor;
string contentID = (string)prop.GetProperty(SchemaPR_ATTACH_CONTENT_ID);
MessageBox.Show("content if is " +contentID);
if (contentID != "")
{
MessageBox.Show("inside if loop");
string filePath = Path.Combine(destinationDirectory, atmt.FileName);
MessageBox.Show(filePath);
atmt.SaveAsFile(filePath);
AttachmentDetails.Add(filePath);
}
else
{
MessageBox.Show("inside else loop");
string filePath = Path.Combine(destinationDirectoryT, atmt.FileName);
atmt.SaveAsFile(filePath);
AttachmentDetails.Add(filePath);
}
}
} …Run Code Online (Sandbox Code Playgroud) 我编写了一个Outlook插件,该插件基本上允许通过Outlook接收的电子邮件与网站链接,以便也可以在网站的通讯功能中查看电子邮件。我将其他详细信息存储在MailItem的ItemProperties中,这些详细信息基本上是类似于网站中与电子邮件相关的用户ID之类的东西。
我遇到的问题是在打印电子邮件时,正在打印添加到MailItem的所有ItemProperties。有谁知道在打印电子邮件时如何排除自定义ItemProperty?
这是创建自定义ItemProperty的代码:
// Try and access the required property.
Microsoft.Office.Interop.Outlook.ItemProperty property = mailItem.ItemProperties[name];
// Required property doesnt exist so we'll create it on the fly.
if (property == null) property = mailItem.ItemProperties.Add(name, Microsoft.Office.Interop.Outlook.OlUserPropertyType.olText);
// Set the value.
property.Value = value;
Run Code Online (Sandbox Code Playgroud) 我正在使用Outlook2013,它有来自交换服务器和pop服务器的多个邮箱.(Rob@mydomain.com [默认交换],rob @ somethingdifferent.com [POP],support@mydomain.com [交换])
我正在尝试使用Outlook自动化使用support@mydomain.com帐户发送电子邮件.
我遇到的问题是下面的代码在支持发件箱中创建了一个邮件项目,但是from字段是rob@mydomain.com而不是support@mydomain.com.这会阻止它被发送.
我想将发件人地址更改为support@mydomain.com.我认为通过设置Sendusingaccount属性就可以了.
任何帮助是极大的赞赏.
public static string Send_Email_Outlook(string _recipient, string _message, string _subject, string _cc, string _bcc, string accountname)
{
try
{
Microsoft.Office.Interop.Outlook.Application oApp = new Microsoft.Office.Interop.Outlook.Application();
// Get the NameSpace and Logon information.
Microsoft.Office.Interop.Outlook.NameSpace oNS = oApp.GetNamespace("mapi");
// Log on by using a dialog box to choose the profile.
oNS.Logon(Missing.Value, Missing.Value, true, true);
// Create a new mail item.
Microsoft.Office.Interop.Outlook.MailItem oMsg = (Microsoft.Office.Interop.Outlook.MailItem)oApp.CreateItem(Microsoft.Office.Interop.Outlook.OlItemType.olMailItem);
// Set the subject.
oMsg.Subject = _subject;
// Set HTMLBody. …Run Code Online (Sandbox Code Playgroud)