本文整理汇总了C#中OpenPop.Pop3.Pop3Client.GetMessage方法的典型用法代码示例。如果您正苦于以下问题:C# Pop3Client.GetMessage方法的具体用法?C# Pop3Client.GetMessage怎么用?C# Pop3Client.GetMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类OpenPop.Pop3.Pop3Client
的用法示例。
在下文中一共展示了Pop3Client.GetMessage方法的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: 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});
}
}
}
示例3: 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;
}
示例4: 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;
}
}
示例5: 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));
}
}
}
示例6: 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);
}
}
}
}
}
示例7: 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;
}
}
示例8: 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));
}
}
示例9: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
try
{
using (Pop3Client client = new Pop3Client())
{
//Para conectar no servidor do gmail use a porta 995 e SSL
client.Connect("pop.gmail.com", 995, true);
//Para conectar no servidor do hotmail use a porta 995 e SSL
//client.Connect("pop3.live.com", 995, true);
//usuário e senha para autenticar
client.Authenticate("luisfelipe.lambert", "sakuda5G");
//Pega o número de mensagens
int messageCount = client.GetMessageCount();
//Instanciar a lista
List<Message> mensagens = new List<Message>();
//Pegar as mensagens
for (int i = messageCount; i > 0; i--)
{
//Adicionar a mensagem a lista
mensagens.Add(client.GetMessage(i));
}
//Popular o repeater com as mensagens
repMensagens.DataSource = mensagens;
repMensagens.DataBind();
}
}
catch (Exception ex)
{
//Caso ocorra algum erro, uma mensagem será exibida na página
litMensagemErro.Text = ex.ToString();
}
}
示例10: 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());
}
}
示例11: 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;
}
}
示例12: GetMessages
public IEnumerable<MessageDTO> GetMessages(string hostname, int port, bool useSsl, string username,
string password, int? maxNumber = null)
{
var allMessages = new List<MessageDTO>();
try
{
// The client disconnects from the server when being disposed
using (var client = new Pop3Client())
{
client.Connect(hostname, port, useSsl);
client.Authenticate(username, password, AuthenticationMethod.UsernameAndPassword);
var maxCount = client.GetMessageCount();
//work out subset to take from messages
var messageCount = (maxNumber.HasValue && maxNumber < maxCount) ? (maxCount - maxNumber.Value) : 0;
//message list is 1 based
//loop written backwards so messages are in correct order
for (var i = maxCount; i > messageCount; i--)
{
var currentMessage = client.GetMessage(i);
var html = currentMessage.FindFirstHtmlVersion();
allMessages.Add(new MessageDTO
{
Body =
html != null && html.Body != null
? Encoding.UTF8.GetString(html.Body)
: string.Empty,
DateSent = currentMessage.Headers.DateSent,
DisplayName = currentMessage.Headers.From.DisplayName,
From = currentMessage.Headers.From.Address,
Id = currentMessage.Headers.MessageId,
Subject = currentMessage.Headers.Subject,
Uid = currentMessage.Headers.MessageId
});
}
}
}
catch (Exception ex)
{
var path = Path.GetTempPath();
var stream = File.OpenWrite(Path.Combine(path, "mailFireErrorLog.log"));
using (var fileWriter = new StreamWriter(stream))
{
fileWriter.Write(string.Format("Exception occurred: {0} - at {1}", ex.Message, DateTime.Now));
}
}
return allMessages;
}
示例13: DownloadMailsAndPushToIssueTracker
private static void DownloadMailsAndPushToIssueTracker()
{
var host = Settings.Get("Pop3Host", "");
var port = Settings.Get("Pop3Port", 110);
var useSsl = Settings.Get("Pop3UseSsl", false);
var username = Settings.Get("Pop3Username", "");
var password = Settings.Get("Pop3Password", "");
if (host.IsNoE())
{
Console.WriteLine("\tNo Pop3Host specified.");
LogOwnError(new ApplicationException("No Pop3Host specified."));
return;
}
try
{
Console.WriteLine("\tConnecting to POP3 server {0}:{1} ({4}) using {2} / {3} ...", host, port, username, password, useSsl ? "SSL" : "no SSL");
using (var pop3Client = new Pop3Client())
{
pop3Client.Connect(host, port, useSsl);
if (username.HasValue())
pop3Client.Authenticate(username, password);
Console.WriteLine("\tFetching message count ...");
var messageCount = pop3Client.GetMessageCount();
for (var i = 1; i <= messageCount; i++)
{
try
{
Console.WriteLine("\tFetching message {0} / {1} ...", i, messageCount);
var message = pop3Client.GetMessage(i);
if (PushToIssueTracker(message))
pop3Client.DeleteMessage(i);
}
catch (Exception ex)
{
Console.WriteLine("\tUnable to fetch or push message: " + ex);
LogOwnError(new ApplicationException("Unable to fetch or push message: " + ex.Message, ex));
}
}
pop3Client.Disconnect();
}
}
catch (Exception ex)
{
Console.WriteLine("\tUnable to download mails: " + ex);
LogOwnError(new ApplicationException("Unable to download mails: " + ex.Message, ex));
}
}
示例14: GetPopEmail
private static GetEmailResponse GetPopEmail()
{
var client = new Pop3Client();
client.Connect("pop.gmail.com", 995, true);
client.Authenticate("[email protected]", "Woq0wy951", AuthenticationMethod.UsernameAndPassword);
var count = client.GetMessageCount();
var message = client.GetMessage(count);
Console.WriteLine(message.Headers.Subject);
return new GetEmailResponse
{
};
}
示例15: GetAllMails
public static List<Message> GetAllMails(string hostname, int port, bool useSsl, string username, string password)
{
using(Pop3Client client = new Pop3Client())
{
client.Connect(hostname, port, useSsl);
client.Authenticate(username, password);
int messageCount = client.GetMessageCount();
Debug.WriteLine(messageCount);
List<Message> allMessages = new List<Message>(messageCount);
for (int i = messageCount; i > 0; i--)
{
allMessages.Add(client.GetMessage(i));
Debug.WriteLine(client.GetMessage(i).MessagePart);
}
return allMessages;
}
}