本文整理汇总了C#中OpenPop.Pop3.Pop3Client类的典型用法代码示例。如果您正苦于以下问题:C# Pop3Client类的具体用法?C# Pop3Client怎么用?C# Pop3Client使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Pop3Client类属于OpenPop.Pop3命名空间,在下文中一共展示了Pop3Client类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Fetch
public void Fetch(Action<Message> process)
{
var seenUids = File.Exists(seenUidsFile) ? new HashSet<string>(File.ReadAllLines(seenUidsFile)) : new HashSet<string>();
using (var client = new Pop3Client())
{
pop3Authorize(client);
List<string> messageUids = client.GetMessageUids();
foreach (var msgInfo in messageUids.Select((uid, index) => new{uid, index}).Where(msgInfo => !seenUids.Contains(msgInfo.uid)))
{
try
{
Message message = client.GetMessage(msgInfo.index+1);
message.Save(new FileInfo(msgInfo.uid + ".mime"));
process(message);
seenUids.Add(msgInfo.uid);
}
catch(Exception e)
{
log.Error("Error while processing message " + msgInfo + "\r\n" + e);
}
}
File.WriteAllLines(seenUidsFile, seenUids);
for(int i=messageUids.Count; i>=1; i--) client.DeleteMessage(i);
}
}
示例2: HasMessages
public override bool HasMessages()
{
if (!pop3Client.Connected)
{
pop3Client.Dispose();
pop3Client = new Pop3Client();
pop3Client.Connect(HostName, Port, useSSL);
pop3Client.Authenticate(Login, Password);
}
if (0 >= index)
{
index = count = pop3Client.GetMessageCount();
if (0 == index)
{
pop3Client.Disconnect();
pop3Client.Dispose();
pop3Client = new Pop3Client();
pop3Client.Connect(HostName, Port, useSSL);
pop3Client.Authenticate(Login, Password);
}
//for (int i = count; i >= 1; i -= 1)
}
return 0 < index;
}
示例3: Test
public void Test()
{
const string hostName = "pop.gmail.com";
int port = 995;
bool useSsl = true;
string userName = "USER";
string password = "PASSWORD";
using(Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostName, port, useSsl);
// Authenticate ourselves towards the server
client.Authenticate(userName, password);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<Message> allMessages = new List<Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
// Most servers give the latest message the highest number
for (int i = messageCount; i > 0; i--)
{
allMessages.Add(client.GetMessage(i));
}
allMessages.ForEach(m=>Console.WriteLine("Display name: {0}", m.Headers.From.DisplayName));
}
}
示例4: GetAllMessages
//Connect to gmail, get emails and ad it to a MessageList
public static List<OpenPop.Mime.Message> GetAllMessages(string hostname, int port, bool ssl, string username, string password)
{
try
{
Pop3Client client = new Pop3Client();
if (client.Connected)
{
client.Disconnect();
}
client.Connect(hostname, port, ssl);
client.Authenticate(username, password);
int messageCount = client.GetMessageCount();
List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);
for (int i = messageCount; i > messageCount - 5; i--)
{
allMessages.Add(client.GetMessage(i));
}
return allMessages;
}
catch(Exception ex)
{
MessageBox.Show("You have written username or password wrong or something else has happened! Program will not keep going, please open it again, thank you : " + ex.Message);
Thread.CurrentThread.Abort();
//EmailClient.
}
return null;
}
示例5: GetAllMails
/* Function to retrive Email from the POP3 Server */
public void GetAllMails(object sender, DoWorkEventArgs e)
{
int percentComplete;
using(Pop3Client client = new Pop3Client())
{
/* Set the Server, Port, ssl and username/password */
client.Connect(Setting.Default.pop3_server, Setting.Default.pop3_port, Setting.Default.smtp_ssl);
client.Authenticate(Setting.Default.username, Setting.Default.password);
int messageCount = client.GetMessageCount();
Debug.WriteLine(messageCount);
/* Create a list to contain the messages */
List<Message> allMessages = new List<Message>();
/* A loop to calculate the progress of retriving the Emails */
for (int i = messageCount; i > 0; i--)
{
allMessages.Add(client.GetMessage(i));
percentComplete = Convert.ToInt16((Convert.ToDouble(allMessages.Count) / Convert.ToDouble(messageCount)) * 100);
(sender as BackgroundWorker).ReportProgress(percentComplete);
}
e.Result = allMessages;
}
}
示例6: ReadAllEmails
private void ReadAllEmails()
{
// The client disconnects from the server when being disposed
using (Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(EmailConfiguration.Pop3, EmailConfiguration.PopPort, true, 1800, 1800, removeCertificateCallback);
// Authenticate ourselves towards the server
client.Authenticate(EmailConfiguration.Email, EmailConfiguration.EmailPwd);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
_systemLogger.Tell(string.Format("Total messages found: {0}", messageCount));
// Most servers give the latest message the highest number
for (int i = messageCount; i > 0; i--)
{
var msg = client.GetMessage(i);
// Now return the fetched messages
_emailProcessorActor.Tell(new EmailMessage(){Subject = msg.Headers.Subject, Date = msg.Headers.Date});
}
}
}
示例7: processMail
public void processMail()
{
Logger.info("Проверка почты: ");
try {
Pop3Client client = new Pop3Client();
client.Connect(Settings.Single.smtpServer, 110, false);
client.Authenticate(Settings.Single.smtpUser, Settings.Single.smtpPassword);
List<string> msgs = client.GetMessageUids();
Logger.info(String.Format("Получено {0} сообщений ", msgs.Count));
for (int i = 0; i < msgs.Count; i++) {
try {
Logger.info("Чтение письма " + i.ToString());
Message msg = client.GetMessage(i);
List<MessagePart> files = msg.FindAllAttachments();
Logger.info(String.Format("Прикреплено {0} файлов", files.Count));
if (files.Count == 1) {
Logger.info(String.Format("Обработка файла {0}", files[0].FileName));
MessagePart file = files[0];
string pbrData = file.GetBodyAsText();
PBR.getFromText(pbrData);
}
}
catch (Exception e) {
Logger.error("Ошибка при обработке письма " + i);
}
}
}
catch (Exception e) {
Logger.error("Ошибка при работе с почтой " + e.ToString());
}
}
示例8: fetchAllMessages
private static void fetchAllMessages(object sender, DoWorkEventArgs e)
{
int percentComplete;
// The client disconnects from the server when being disposed
using (Pop3Client client = new Pop3Client())
{
// Connect to the server
//client.Connect("pop.gmail.com", 995, true);
client.Connect("mail1.stofanet.dk", 110, false);
// Authenticate ourselves towards the server
client.Authenticate("2241859m002", "big1234");
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<OpenPop.Mime.Message> allMessages = new List<OpenPop.Mime.Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
// Most servers give the latest message the highest number
for (int i = messageCount; i > 0; i--)
{
allMessages.Add(client.GetMessage(i));
percentComplete = Convert.ToInt16((Convert.ToDouble(allMessages.Count) / Convert.ToDouble(messageCount)) * 100);
(sender as BackgroundWorker).ReportProgress(percentComplete);
}
// Now return the fetched messages
e.Result = allMessages;
}
}
示例9: ImportEmails
//-------------------------------------------------------------------------------------------
private void ImportEmails(Communication_EmailAccounts account)
{
Console.WriteLine("Importing e-mails for " + account.Id + " -- " + account.Host);
using (Pop3Client client = new Pop3Client())
{
// connect
client.Connect(account.Host, account.Port, (account.Type == "pops"));
client.Authenticate(account.Username, account.Password);
// iterate over the messages
int messageCount = client.GetMessageCount();
List<Message> allMessages = new List<Message>(messageCount);
for (int i = 1; i <= messageCount; i++)
{
using (WeavverEntityContainer data = new WeavverEntityContainer())
{
//data.SearchAllTables("asdf");
// save to database
Message m = (Message) client.GetMessage(i);
if (m.MessagePart.IsText)
{
Communication_Emails item = new Communication_Emails();
item.From = m.Headers.From.Raw;
item.Subject = m.Headers.Subject;
item.Raw = System.Text.ASCIIEncoding.ASCII.GetString(m.RawMessage);
data.SaveChanges();
client.DeleteMessage(i);
}
}
}
}
}
示例10: FetchAllMessages
/// <summary>
/// Example showing:
/// - how to fetch all messages from a POP3 server
/// </summary>
/// <param name="hostname">Hostname of the server. For example: pop3.live.com</param>
/// <param name="port">Host port to connect to. Normally: 110 for plain POP3, 995 for SSL POP3</param>
/// <param name="useSsl">Whether or not to use SSL to connect to server</param>
/// <param name="username">Username of the user on the server</param>
/// <param name="password">Password of the user on the server</param>
/// <returns>All Messages on the POP3 server</returns>
public static List<Message> FetchAllMessages(string hostname, int port, bool useSsl, string username, string password)
{
// The client disconnects from the server when being disposed
using(Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(hostname, port, useSsl);
// Authenticate ourselves towards the server
client.Authenticate(username, password);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<Message> allMessages = new List<Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
// Most servers give the latest message the highest number
for (int i = messageCount; i > 0; i--)
{
allMessages.Add(client.GetMessage(i));
}
// Now return the fetched messages
return allMessages;
}
}
示例11: ConnectToPop3
private void ConnectToPop3()
{
client = new Pop3Client();
client.Connect(settings.Pop3Server, settings.Pop3Port, settings.Pop3UseSSL);
client.Authenticate(settings.Pop3UserName, settings.Pop3Password);
}
示例12: TestMethodInitialize
public void TestMethodInitialize()
{
settings = new TestSettings();
client = new Pop3Client();
client.Connect(settings.Pop3Server, settings.Pop3Port, settings.Pop3UseSSL);
client.Authenticate(settings.Pop3UserName, settings.Pop3Password);
}
示例13: FetchAllMessages
public void FetchAllMessages()
{
// The client disconnects from the server when being disposed
using (Pop3Client client = new Pop3Client())
{
// Connect to the server
client.Connect(_hostName, _port, true);
// Authenticate ourselves towards the server
client.Authenticate(_username, _password);
// Get the number of messages in the inbox
int messageCount = client.GetMessageCount();
// We want to download all messages
List<Message> allMessages = new List<Message>(messageCount);
// Messages are numbered in the interval: [1, messageCount]
// Ergo: message numbers are 1-based.
for (int i = 1; i <= messageCount; i++)
{
allMessages.Add(client.GetMessage(i));
}
}
}
示例14: TestAutoAuthenticationUsernameAndPassword
public void TestAutoAuthenticationUsernameAndPassword()
{
const string welcomeMessage = "+OK POP3 server ready";
const string okUsername = "+OK";
const string loginMessage = "+OK mrose's maildrop has 2 messages (320 octets)";
const string serverResponses = welcomeMessage + "\r\n" + okUsername + "\r\n" + loginMessage + "\r\n";
Stream inputStream = new MemoryStream(Encoding.ASCII.GetBytes(serverResponses));
MemoryStream outputStream = new MemoryStream();
Pop3Client client = new Pop3Client();
client.Connect(new CombinedStream(inputStream, outputStream));
// The Pop3Client should now have seen, that the server does not support APOP
Assert.IsFalse(client.ApopSupported);
client.Authenticate("mrose", "tanstaaf");
string[] commandsFired = GetCommands(new StreamReader(new MemoryStream(outputStream.ToArray())).ReadToEnd());
const string firstCommand = "USER mrose";
Assert.AreEqual(firstCommand, commandsFired[0]);
const string secondCommand = "PASS tanstaaf";
Assert.AreEqual(secondCommand, commandsFired[1]);
}
示例15: Form1
public Form1(String pas_)
{
InitializeComponent();
pop3Client = new Pop3Client();
System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;
passEMAIL = pas_;
}