MailClient.AppendEx Method


Appends an email to specified IMAP4/Exchange folder with flags.

[Visual Basic]
Public Sub AppendEx( _
    folder As Imap4Folder, _
    data() As Byte, _
    flags As String _
)

Public Async Function AppendExAsync( _
    folder As Imap4Folder, _
    data() As Byte, _
    flags As String _
) As Task

Public Sub AppendEx( _
    folder As Imap4Folder, _
    data() As Byte, _
    flags As String, _
    dt As System.DateTime _
)

Public Async Function AppendExAsync( _
    folder As Imap4Folder, _
    data() As Byte, _
    flags As String, _
    dt As System.DateTime _
) As Task
[C#]
public void AppendEx(
    Imap4Folder folder,
    byte[] data,
    string flags
);

public async Task AppendExAsync(
    Imap4Folder folder,
    byte[] data,
    string flags
);

public void AppendEx(
    Imap4Folder folder,
    byte[] data,
    string flags,
    System.DateTime dt
);

public async Task AppendExAsync(
    Imap4Folder folder,
    byte[] data,
    string flags,
    System.DateTime dt
);
[C++]
public: void AppendEx(
    Imap4Folder^ folder,
    array<unsigned char>^ data,
    String^ flags
);

public: void AppendEx(
    Imap4Folder^ folder,
    array<unsigned char^> data,
    String^ flags,
    System::DateTime dt
);
[JScript]
public function AppendEx( 
    folder: Imap4Folder,
    data: Byte [],
    flags: String
);

public function AppendEx( 
    folder: Imap4Folder,
    data: Byte [],
    flags: String,
    dt: System.DateTime
);

Parameters

folder
The dest IMAP/Exchange folder.
data
The binary data of email.
flags
The flags of email, the value can be \Seen, \Deleted or (\Seen \Deleted). For Exchange Web Service/WebDAV protocol, please use zero-length string.
dt
The datetime assigned to the email.For Exchange Web Service/WebDAV protocol, please use current system date time.

Example

[Visual Basic, C#, C++] The following example demonstrates how to append email to "INBOX" with EAGetMail POP3 & IMAP Component. To get the full samples of EAGetMail, please refer to Samples section.

[VB - Upload email to specified folder]
Imports System
Imports System.Globalization
Imports System.IO
Imports System.Text
Imports EAGetMail

Public Class TestClass
    ' if you want to search sub folder, use parentfolder\subfolder as folderPath
    ' for example: inbox\mysubfolder
    Function FindFolder(ByVal folderPath As String, ByRef folders As Imap4Folder()) As Imap4Folder
        For i As Integer = 0 To folders.Length - 1
            Dim folder As Imap4Folder = folders(i)
            ' Folder was found.
            If String.Compare(folder.LocalPath, folderPath, True) = 0 Then
                Return folder
            End If

            folder = FindFolder(folderPath, folder.SubFolders)
            If Not (folder Is Nothing) Then
                Return folder
            End If
        Next

        ' No folder found
        Return Nothing
    End Function

    Public Sub AppendEmail(emlFile As String, server As String, user As String, password As String, useSsl As Boolean)
        Try
            ' load file
            Dim oMail As New Mail("TryIt")
            oMail.Load(emlFile, False)

            ' ExchangeEWS Or ExchangeWebDAV protocol also supports Append method.

            ' Most modern email servers require SSL/TLS connection, 
            ' set useSsl to true Is recommended.
            Dim oServer As New MailServer(server, user, password, useSsl,
                        ServerAuthType.AuthLogin, ServerProtocol.Imap4)

            ' IMAP4 port Is 143,  IMAP4 SSL port Is 993.
            ' EWS/WebDAV, please ignore Port property.
            oServer.Port = If(useSsl, 993, 143)

            Console.WriteLine("Connecting server ...")
            Dim oClient As New MailClient("TryIt")
            oClient.Connect(oServer)

            ' Find dest folder based on path.
            Dim folder As Imap4Folder = FindFolder("Inbox", oClient.GetFolders())
            If folder Is Nothing Then
                Throw New Exception("Dest folder was not found")
            End If

            ' Appends this email to "INBOX" folder
            Console.WriteLine("Uploading email file ...")
            oClient.AppendEx(folder, oMail.Content, "\Seen \Deleted")

            oClient.Logout()
            Console.WriteLine("Completed!")
        Catch ep As Exception
            Console.WriteLine(ep.Message)
        End Try
    End Sub

End Class


[C# - Upload email to specified folder] using System; using System.IO; using System.Globalization; using System.Text; using EAGetMail; class TestClass { // if you want to search sub folder, use parentfolder\subfolder as folderPath // for example: inbox\mysubfolder static Imap4Folder FindFolder(string folderPath, Imap4Folder[] folders) { int count = folders.Length; for (int i = 0; i < count; i++) { Imap4Folder folder = folders[i]; if (string.Compare(folder.LocalPath, folderPath, true) == 0) { return folder; } folder = FindFolder(folderPath, folder.SubFolders); if (folder != null) { return folder; } } // No folder found return null; } public void AppendEmail(string emlFile, string server, string user, string password, bool useSsl) { try { // load file Mail oMail = new Mail("TryIt"); oMail.Load(emlFile, false); // ExchangeEWS or ExchangeWebDAV protocol also supports Append method. // Most modern email servers require SSL/TLS connection, // set useSsl to true is recommended. MailServer oServer = new MailServer(server, user, password, useSsl, ServerAuthType.AuthLogin, ServerProtocol.Imap4); // IMAP4 port is 143, IMAP4 SSL port is 993. // EWS/WebDAV, please ignore Port property. oServer.Port = (useSsl) ? 993 : 143; Console.WriteLine("Connecting server ..."); MailClient oClient = new MailClient("TryIt"); oClient.Connect(oServer); // find dest folder Imap4Folder folder = FindFolder("Inbox", oClient.GetFolders()); if (folder == null) { throw new Exception("Dest folder not found!"); } // appends this email to "INBOX" folder Console.WriteLine("Uploading email file ..."); oClient.AppendEx(folder, oMail.Content, "\\Seen \\Deleted"); oClient.Logout(); Console.WriteLine("Completed!"); } catch (Exception ep) { Console.WriteLine("Error: {0}", ep.Message); } } }
[C++/CLI - Upload email to specified folder] using namespace System; using namespace System::Globalization; using namespace System::IO; using namespace EAGetMail; //add EAGetMail namespace // if you want to search sub folder, use parentfolder\\subfolder as folderPath // for example: inbox\\mysubfolder Imap4Folder^ FindFolder(String^ folderPath, array<Imap4Folder^> ^folders) { for (int i = 0; i < folders->Length; i++) { Imap4Folder^ folder = folders[i]; // Folder was found. if (String::Compare(folder->LocalPath, folderPath, true) == 0) return folder; folder = FindFolder(folderPath, folder->SubFolders); if (folder != nullptr) return folder; } // No folder found return nullptr; } void AppendEmail(String ^emlFile, String ^server, String ^user, String ^password, bool useSsl) { try { // load file Mail^ oMail = gcnew Mail("TryIt"); oMail->Load(emlFile, false); // ExchangeEWS or ExchangeWebDAV protocol also supports Append method. // Most modern email servers require SSL/TLS connection, // set useSsl to true is recommended. MailServer ^oServer = gcnew MailServer(server, user, password, useSsl, ServerAuthType::AuthLogin, ServerProtocol::Imap4); // IMAP4 port is 143, IMAP4 SSL port is 993. // EWS/WebDAV, please ignore Port property. oServer->Port = (useSsl) ? 993 : 143; Console::WriteLine("Connecting server ..."); MailClient ^oClient = gcnew MailClient("TryIt"); oClient->Connect(oServer); // find dest folder Imap4Folder ^ folder = FindFolder("Inbox", oClient->GetFolders()); if (folder == nullptr) { throw gcnew Exception("Dest folder not found!"); } // appends email to "INBOX" Console::WriteLine("Uploading email file ..."); oClient->AppendEx(folder, oMail->Content, "\\Seen \\Deleted"); oClient->Logout(); Console::WriteLine("Completed!"); } catch (Exception ^ep) { Console::WriteLine("Error: {0}", ep->Message); } }

See Also

MailClient.Append Method
MailClient.SelectFolder Method