if (_tbMessageFilename.Text == string.Empty)
{
this.AddLogEntry("You have to set a directory to store the attachments.");
}
else
{
// We instantiate the pop3 client.
Pop3Client pop = new Pop3Client();
try
{
this.AddLogEntry(string.Format("Connection to the pop 3 server : {0}", _tbPop3Server));
// Connect to the pop3 client
pop.Connect(_tbPop3Server.Text, _tbUserName.Text, _tbPassword.Text);
if (pop.MessageCount > 0)
{
ActiveUp.Net.Mail.Message message = pop.RetrieveMessageObject(1);
if (message.Attachments.Count > 0)
{
// Save the first attachment to the specified directory.
message.Attachments[0].StoreToFile(_fbdSaveDirectory.SelectedPath + message.Attachments[0].HeaderFields["FileName"]);
this.AddLogEntry("Attachments '{0}' saved successfully.", message.Attachments[0].HeaderFields["FileName"]);
}
else
{
this.AddLogEntry("There is no attachments in the message.");
}
}
else
{
this.AddLogEntry("There is no message in this pop3 account");
}
}
catch (Pop3Exception pexp)
{
this.AddLogEntry(string.Format("Pop3 Error: {0}", pexp.Message));
}
catch (Exception ex)
{
this.AddLogEntry(string.Format("Failed: {0}", ex.Message));
}
finally
{
if (pop.IsConnected)
{
pop.Disconnect();
}
}