从G-Mail获取电子邮件 [英] Get Email From G-Mail
本文介绍了从G-Mail获取电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想从G-Mail检索邮件。起初我使用POP但是一段时间后它没有正常工作。有人可以用一段代码帮助我。我正在使用Windows表格c#。提前谢谢。
解决方案
查看以下链接了解更多信息。
/// < 摘要 >
/// 示例显示:
/// - 如何从POP3服务器获取所有消息
/// < / summary >
/// < pa ram name =hostname > 服务器的主机名。例如:pop3.live.com < / param >
/// < param name =port > 要连接的主机端口。通常:普通POP3为110,SSL POP3为995 < / param >
/// < param name =useSsl > 是否使用SSL连接服务器< / param >
/// < param name =username > 服务器上用户的用户名< / param >
/// < param name =密码 > 服务器上用户的密码< / param >
/// < 返回 > POP3服务器上的所有消息< / ret骨灰盒 >
public static 列表<消息> FetchAllMessages( string hostname, int port, bool useSsl, string username, string password)
{
// 客户端在处理时与服务器断开连接
使用(Pop3Client client = new Pop3Client())
{
// 连接到服务器
client.Connect(hostname,port,useSsl);
// 向服务器验证我们自己
client.Authenticate (用户名密码);
// 获取收件箱中的邮件数量
int messageCount = client.GetMessageCount();
// 我们要下载所有消息
List<消息> allMessages = new 列表<消息>(messageCount);
// 消息在间隔中编号:[1,messageCount]
// Ergo:消息编号从1开始。
// 大多数服务器提供最新消息
for ( int i = messageCount; i > 0 ; i--)
{
allMessages.Add(client.GetMessage(i));
}
// 现在返回已获取的消息
return allMessages;
}
}
按照我之前的回答 - 使用EAGetMail组件从Gmail服务器读取电子邮件 [ ^ ]。
i want to retrieve mail from G-Mail. At first i used POP but after some time it was not working fine. can somebody help me with a piece of code. I am using windows form c#.Thanks in advance.
解决方案
Check below link for more info.
/// <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; } }
Follow my previous answer- Read Email from Gmail Server using EAGetMail component[^].
这篇关于从G-Mail获取电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文