嘿伙计们,我们有一个私人电子邮件服务器在工作,我需要编写一个电子邮件客户端供所有开发人员使用。我已经让它毫无问题地发送电子邮件,但我似乎无法让它检索电子邮件。根据验证程序,我收到一条错误消息,指出远程证书无效。我们在电子邮件服务器中使用代理,但他们在我的黑莓上设置了一个外部地址它可以 100% 工作我可以发送和接收电子邮件但在这个应用程序中它不会......我搜索了谷歌并得到我需要禁用 ssl 验证我做了证书女巫,但我仍然得到错误。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Net.Mail;
using System.Configuration;
using System.Net;
using System.Net.Security;
using OpenPop.Pop3;
using OpenPop.Mime;
using System.IO;
using System.Security;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
using System.Security.Policy;
namespace VeriChat
{
public partial class Mail : UserControl
{
string Email = "";
string Password = "";
public Mail()
{
InitializeComponent();
}
private void lblTime_Loaded(object sender, RoutedEventArgs e)
{
VeriChatMain v = new VeriChatMain();
Email = v.Email;
Password = v.Password;
System.Windows.Threading.DispatcherTimer timer = new System.Windows.Threading.DispatcherTimer();
timer.Tick += new EventHandler(timer_Tick);
timer.Interval = new TimeSpan(0, 0, 1);
timer.Start();
Retrieve();
}
private void timer_Tick(object sender, EventArgs e)
{
lblTime.Content = DateTime.Now.ToString();
}
private void btnNewEmail_Click(object sender, RoutedEventArgs e)
{
SendEmail se = new SendEmail();
se.ShowDialog();
}
public void Retrieve()
{
ServicePointManager.ServerCertificateValidationCallback = delegate(object s, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{
return true;
};
var client = new Pop3Client();
client.Connect("example.com", 995, true);
client.Authenticate("username", "password");
var count = client.GetMessageCount();
Message message = client.GetMessage(count);
StreamWriter sw = new StreamWriter(@"downloads.txt", true);
sw.WriteLine(message.Headers.Subject);
sw.Close();
}
}
}