Dim curpath As String = Directory.GetCurrentDirectory()
Dim mailbox As String = [String].Format("{0}\inbox", curpath)
' If the folder is not existed, create it.
If Not Directory.Exists(mailbox) Then
Directory.CreateDirectory(mailbox)
End If
' Gmail IMAP server is "imap.gmail.com"
Dim oServer As New MailServer("imap.gmail.com", _
"snshanjava@gmail.com", "pvohhnsducvzfclx", ServerProtocol.Imap4)
Dim oClient As New MailClient("TryIt")
' Enable SSL connection
oServer.SSLConnection = True
' Set IMAP4 SSL port
oServer.Port = 993
Try
oClient.Connect(oServer)
Dim infos As MailInfo() = oClient.GetMailInfos()
For i As Integer = 0 To infos.Length - 1
Dim info As MailInfo = infos(i)
Console.WriteLine("Index: {0}; Size: {1}; UIDL: {2}", _
info.Index, info.Size, info.UIDL)
' Receive email from Gmail server
Dim oMail As Mail = oClient.GetMail(info)
Console.WriteLine("From: {0}", oMail.From.ToString())
Console.WriteLine("Subject: {0}" & vbCr & vbLf, oMail.Subject)
Dim imapMessageCollection
' Generate an email file name based on date time.
Dim d As System.DateTime = System.DateTime.Now
Dim cur As New System.Globalization.CultureInfo("en-US")
Dim sdate As String = d.ToString("yyyyMMddHHmmss", cur)
Dim fileName As String = [String].Format("{0}\{1}{2}{3}.eml", _
mailbox, sdate, d.Millisecond.ToString("d3"), i)
' Save email to local disk
oMail.SaveAs(fileName, True)
' Mark email as deleted in Gmail Account
oClient.Delete(info)
Next
' Quit and pure emails marked as deleted from Gmail IMAP4 server.
oClient.Quit()
Catch ep As Exception
Console.WriteLine(ep.Message)
End Try
在上面的代码中,我从gmail服务器下载邮件,将这些邮件保存到本地文件夹" Inbox" .mail完全下载,但从这里我只想获得那些邮件的消息体,并在我的应用程序的网格视图中显示。我不知道这个。我在上面的代码中要做什么
有人在此事先帮助解决了这个问题。