Appends an email to specified IMAP4/Exchange folder.
[Visual Basic]
Public Sub Append( _
folder As Imap4Folder, _
data() As Byte _
)
Public Async Function AppendAsync( _
folder As Imap4Folder, _
data() As Byte _
) As Task
[C#]
public void Append(
Imap4Folder folder,
byte[] data
);
public async Task AppendAsync(
Imap4Folder folder,
byte[] data
);
[C++]
public: void Append(
Imap4Folder^ folder,
array<unsigned char^> data
);
[JScript]
public function Append(
folder: Imap4Folder,
data: Byte []
);
Parameters
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.Append(folder, oMail.Content)
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.Append(folder, oMail.Content);
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->Append(folder, oMail->Content);
oClient->Logout();
Console::WriteLine("Completed!");
}
catch (Exception ^ep)
{
Console::WriteLine("Error: {0}", ep->Message);
}
}
See Also