- 最後登錄
- 2023-4-24
- 在線時間
- 186 小時
- 註冊時間
- 2008-4-1
- 閱讀權限
- 20
- 精華
- 0
- UID
- 3887184
- 帖子
- 372
- 積分
- 21 點
- 潛水值
- 5911 米
| 這裡有一段程式,供參考看看- Imports System.IO
- Imports EAGetMail 'imports EAGetMail namespace
- Module Module1
- Sub Main()
- ' Create a folder named "inbox" under current directory
- ' to save the email retrieved.
- 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", _
- "gmailid@gmail.com", "yourpassword", 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)
- ' 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
- End Sub
- End Module
複製代碼 ... |
|