原創|使用教程|編輯:黃竹雯|2017-06-15 14:34:48.000|閱讀 253 次
概述:本文主要介紹了接收電子郵件(POP3)的代碼示例。目前MailBee.NET Objects在線訂購享75折優惠正在進行中,歡迎您下載試用版進行運用!
# 界面/圖表報表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關鏈接:
C#:
Pop3 pop = new Pop3();
|
VB.NET:
Dim pop As Pop3 = New Pop3() |
C#:
pop.Connect("mail.domain.com");
|
VB.NET:
pop.Connect("mail.domain.com") |
C#:
pop.Connect("127.0.0.1");
|
VB.NET:
pop.Connect("127.0.0.1") |
C#:
pop.Login("login", "password");
|
VB.NET: pop.Login("login", "password") |
C#:
MailMessage msg = pop.DownloadEntireMessage(pop.InboxMessageCount);
|
VB.NET: Dim msg As MailMessage = pop.DownloadEntireMessage(pop.InboxMessageCount) |
C#:
pop.Disconnect();
|
VB.NET: pop.Disconnect() |
C#:
using System;
using MailBee; using MailBee.Pop3Mail; using MailBee.Mime; namespace EmailApp
{ class Class1 { [STAThread] static bool IsNewMessage(string UID)
{ return true; } static void Main(string[] args) { Pop3 pop = new Pop3(); try
{ pop.Connect("mail.domain.com"); pop.Login("login", "password"); Console.WriteLine("Successfully logged in."); } catch(MailBeePop3LoginNegativeResponseException) { Console.WriteLine("POP3 server replied with a negative response at login."); } string[] arrIDs = pop.GetMessageUids();
int n = pop.InboxMessageCount; if (IsNewMessage(arrIDs[n])) { MailMessage msg = pop.DownloadEntireMessage(n); if (msg.BodyHtmlText != "")
Console.WriteLine(msg.BodyHtmlText); else if (msg.BodyPlainText != "") Console.WriteLine(msg.BodyPlainText); else Console.WriteLine("The body of this message is empty."); } try
{ pop.Disconnect(); Console.WriteLine("Disconnected successfully."); } catch
{ Console.WriteLine("Disconnection failed."); } } } } |
VB.NET: Imports System Imports MailBee Imports MailBee.Pop3Mail Imports MailBee.Mime Namespace EmailApp Class Class1 <STAThread> _ Shared Function IsNewMessage(ByVal UID As String) As Boolean Return True End Function Shared Sub Main(ByVal args() As String) Dim pop As Pop3 = New Pop3() Try pop.Connect("mail.domain.com") pop.Login("login", "password") Console.WriteLine("Successfully logged in.") Catch Console.WriteLine("POP3 server replied with a negative response at login.") End Try Dim arrIDs() As String = pop.GetMessageUids() Dim n As Integer = pop.InboxMessageCount If IsNewMessage(arrIDs(n)) Then Dim msg As MailMessage = pop.DownloadEntireMessage(n) If msg.BodyHtmlText <> "" Then Console.WriteLine(msg.BodyHtmlText) Else If msg.BodyPlainText <> "" Then Console.WriteLine(msg.BodyPlainText) Else Console.WriteLine("The body of this message is empty.") End If End If End If Try pop.Disconnect() Console.WriteLine("Disconnected successfully.") Catch Console.WriteLine("Disconnection failed.") End Try End Sub End Class End Namespace |
本站文章除注明轉載外,均為本站原創或翻譯。歡迎任何形式的轉載,但請務必注明出處、不得修改原文相關鏈接,如果存在內容上的異議請郵件反饋至chenjj@fc6vip.cn