如何在.NET应用程序中将邮件从一个邮箱文件夹复制到另一个邮箱文件夹
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在.NET应用程序中将邮件从一个邮箱文件夹复制到另一个邮箱文件夹相关的知识,希望对你有一定的参考价值。
This technical tip explains how .NET developers can Copy Message from one Mailbox folder to another. Aspose.Email API provides the capability to copy message from one mailbox folder to another. It allows copying a single as well as multiple messages using the CopyMessage and CopyMessages methods. The CopyMessages method provides the capability to copy multiple messages from source folder of a mailbox to the destination mailbox folder. The following code sample illustrates this by copying two messages.
//Copying Multiple Messages From One Folder to Another //[C# Code Sample] { //create the destination folder string folderName = "EMAILNET-35242"; if (!client.ExistFolder(folderName)) client.CreateFolder(folderName); try { //Append a couple of messages to the server "EMAILNET-35242 - " + Guid.NewGuid().ToString(), "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation."); string uniqueId1 = client.AppendMessage(message1); "EMAILNET-35242 - " + Guid.NewGuid().ToString(), "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation."); string uniqueId2 = client.AppendMessage(message2); //verify that the messages have been added to the mailbox client.SelectFolder(ImapFolderInfo.InBox); ImapMessageInfoCollection msgsColl = client.ListMessages(); foreach (ImapMessageInfo msgInfo in msgsColl) Console.WriteLine(msgInfo.Subject); //copy multiple messages using hte CopyMessages command //Verify that messages are copied to the destination folder client.SelectFolder(folderName); msgsColl = client.ListMessages(); foreach (ImapMessageInfo msgInfo in msgsColl) Console.WriteLine(msgInfo.Subject); } finally { try { client.DeleteFolder(folderName); } catch { } } } //[VB.NET Code Sample] 'create the destination folder Dim folderName As String = "EMAILNET-35242" If Not client.ExistFolder(folderName) Then client.CreateFolder(folderName) End If Try 'Append a couple of messages to the server Dim message1 As New MailMessage("[email protected]", "[email protected]", "EMAILNET-35242 - " + Guid.NewGuid().ToString(), "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.") Dim uniqueId1 As String = client.AppendMessage(message1) Dim message2 As New MailMessage("[email protected]", "[email protected]", "EMAILNET-35242 - " + Guid.NewGuid().ToString(), "EMAILNET-35242 Improvement of copy method.Add ability to 'copy' multiple messages per invocation.") Dim uniqueId2 As String = client.AppendMessage(message2) 'verify that the messages have been added to the mailbox client.SelectFolder(ImapFolderInfo.InBox) Dim msgsColl As ImapMessageInfoCollection = client.ListMessages() For Each msgInfo As ImapMessageInfo In msgsColl Console.WriteLine(msgInfo.Subject) Next 'copy multiple messages using hte CopyMessages command 'Verify that messages are copied to the destination folder client.SelectFolder(folderName) msgsColl = client.ListMessages() For Each msgInfo As ImapMessageInfo In msgsColl Console.WriteLine(msgInfo.Subject) Next Finally Try client.DeleteFolder(folderName) Catch End Try End Try End Using
以上是关于如何在.NET应用程序中将邮件从一个邮箱文件夹复制到另一个邮箱文件夹的主要内容,如果未能解决你的问题,请参考以下文章
C# 如何从 Outlook 的共享邮箱发送邮件并将其保存在已发送文件夹中
263企业邮箱 如何在Outlook邮件客户端中设置IMAP收发邮件