.net mapi_使用C#.NET通过MAPI访问收件箱

.net mapi

本文讨论了如何使用C#.NET通过MAPI访问收件箱。 它还讨论了如何将附件存储在本地目录中,如何在收件箱中创建文件夹

需要添加参考

Microsoft CDO 1.21库到项目

//Declarations
MAPI.Message objMsg, objMsg_Arch;
MAPI.Messages objMsgs;
MAPI.Attachment objAttach;
MAPI.Attachments objAttachments;
MAPI.Folder objFolder;
MAPI.AddressEntry objAddressEntry;
int intTotalMsgs;
string strLocalDir; 
//To get the total message count in the inbox
objFolder = (Folder)objSession.Inbox;
objMsgs = (Messages)objFolder.Messages;
intTotalMsgs = (int)objMsgs.Count; 
//To get the sender
objMsg = (MAPI.Message)(objMsgs.get_Item(intMsgLoop));
objAddressEntry = (AddressEntry)objMsg.Sender; 
//To save the attachment to local disk
objAttachments = (Attachments)objMsg.Attachments;
objAttach = (Attachment)objAttachments.get_Item(intMsg);
if ((CdoAttachmentType)objAttach.Type == CdoAttachmentType.CdoFileData)
{
    objAttach.WriteToFile(strLocalDir + objAttach.Name.ToString());
} 
//To create a folder in the inbox
Folder objFolder;
Folders objFolders;
Folder objItemFolder;
int intFolderCount;
string strFldrArch;
bool blnOK; 
objFolder = (Folder)objSession.Inbox;
objFolder = (Folder)objSession.GetFolder(objFolder.ID,objFolder.StoreID);
objFolders = (Folders) objFolder.Folders;
intFolderCount = (int)objFolders.Count; 
for (int intLoop = 1; intLoop <= intFolderCount; intLoop++)
{
   objItemFolder = (Folder)objFolders.get_Item(intLoop);
   if (objItemFolder.Name.ToString() == strFldrArch)
   {
       blnOK = true;
       objFolder = objItemFolder;
       break;
   }
}
if (!blnOK)
{
   objFolder = (Folder)objFolders.Add(strFldrArch);
   objFolder.Update(Missing.Value, Missing.Value);
} 
//To delete the message from the inbox
objMsg.Delete(Missing.Value); 
//To forward the message
Message objMsgFwd;
Recipients objRecipients; 
objMsgFwd = (MAPI.Message)objMsg.Forward();
objRecipients = (Recipients)objMsgFwd.Recipients;
objRecipients.Add(<RecipientAddr>, Missing.Value, CdoRecipientType.CdoTo, 
Missing.Value);
objMsgFwd.Text = <Body Message>;
objMsgFwd.Recipients = objRecipients;                                                    objRecipients.Resolve(Missing.Value);
objMsgFwd.Send(false, Missing.Value, Missing.Value); 
//To move the message to a folder
object objFolderID, objStoreID;
objFolderID = objFolder.ID; //objFolder is the folder where the msg to 
be moved
objStoreID = objFolder.StoreID;
objMsgArch = (MAPI.Message)objMsg.MoveTo(objFolderID, objStor 

翻译自: https://bytes.com/topic/net/insights/795371-accessing-inbox-through-mapi-using-c-net

.net mapi

  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

表情包
插入表情
评论将由博主筛选后显示,对所有人可见 | 还能输入1000个字符
©️2021 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值