Hi guys,
the updated nuget package is published.
Greets,
Pavel
the updated nuget package is published.
Greets,
Pavel
client = New ImapX.ImapClient("imap.gmail.com", True)
client.Connect()
client.Login("Email", "Password")
client.Behavior.NoopIssueTimeout = 120
client.Behavior.AutoPopulateFolderMessages = True
Try
dim myinbox = client.Folders.inbox
For Each Message In myinbox.messages
'save them into an array
Next
/// <summary>
/// Connects to an IMAP server on the specified port
/// </summary>
/// <param name="host">Server address</param>
/// <param name="port">Server port</param>
/// <param name="sslProtocol">SSL protocol to use, <code>SslProtocols.None</code> by default</param>
/// <param name="validateServerCertificate">Defines whether the server certificate should be validated when SSL is used</param>
/// <param name="throwExceptionOnError">Rethrows the exception in case of problems. This helps to analyze connections problems</param>
/// <returns><code>true</code> if the connection was successful</returns>
/// <exception cref="Exceptions.InvalidStateException">If the client is already connected.</exception>
public bool Connect(string host, int port, SslProtocols sslProtocol = SslProtocols.None,
bool validateServerCertificate = true, bool throwExceptionOnError = false)
{
_host = host;
_port = port;
_sslProtocol = sslProtocol;
_validateServerCertificate = validateServerCertificate;
if (IsConnected)
throw new InvalidStateException("The client is already connected. Please disconnect first.");
try
{
#if !WINDOWS_PHONE && !NETFX_CORE
_client = new TcpClient(_host, _port);
if (_sslProtocol == SslProtocols.None)
{
_ioStream = _client.GetStream();
_streamReader = new StreamReader(_ioStream);
}
else
{
_ioStream = new SslStream(_client.GetStream(), false, CertificateValidationCallback, null);
(_ioStream as SslStream).AuthenticateAsClient(_host, null, _sslProtocol, false);
_streamReader = new StreamReader(_ioStream);
}
#else
//TODO: Add support for Tls
_client = _sslProtocol == SslProtocols.None ? new TcpClient(_host, _port) : new SecureTcpClient(_host, _port);
_ioStream = _client.GetStream();
_streamReader = new StreamReader(_ioStream);
#endif
string result = _streamReader.ReadLine();
_lastActivity = DateTime.Now;
if (result != null && result.StartsWith(ResponseType.ServerOk))
{
Capability();
return true;
}
else if (result != null && result.StartsWith(ResponseType.ServerPreAuth))
{
IsAuthenticated = true;
Capability();
return true;
}
else
return false;
}
catch (Exception)
{
if (throwExceptionOnError)
throw;
return false;
}
finally
{
if (!IsConnected)
CleanUp();
}
}
Regards //using ImapX_1.2.3.126.zip reference to .dll
ImapX.ImapClient client = new ImapX.ImapClient("imap.gmail.com", 993, true);
bool result = client.Connection();
if (result)
{
result = client.LogIn("test_account@gmail.com", "password");
if (result)
{
textBox1.AppendText(Environment.NewLine + Environment.NewLine + "Log-on successful" +
Environment.NewLine + Environment.NewLine);
ImapX.FolderCollection folders = client.Folders;
foreach (ImapX.Message m in client.Folders["INBOX"].Messages)
{
m.Process();
//if (m.Subject == "test email with 3 attachments (txt, png, wav)")
if (m.Subject == "test email")
{
textBox1.AppendText(Environment.NewLine + Environment.NewLine + "Found email in question..." +
Environment.NewLine + Environment.NewLine);
string path = Application.StartupPath + "\\email\\";
string filename = "test.txt";
//comment-out following line if you don't want to d/l the actual email
m.SaveAsEmlToFile(path, filename);
//use above line, and comment out the following if(){}, if you prefer to download the whole
//email in .eml format
if (m.Attachments.Count > 0)
{
for (int i = 0; i < m.Attachments.Count; i++)
{
m.Attachments[i].SaveFile(path);
textBox1.AppendText("Saved attachment #" + (i + 1).ToString());
textBox1.AppendText(Environment.NewLine + Environment.NewLine);
}
}
}
}
}
}
else
{
textBox1.AppendText("connection failed");
}
First of all, Please forgive the newbie request here.