首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用c# wpf中的pop3将邮件接收到私人邮件服务器时出错

使用c# wpf中的pop3将邮件接收到私人邮件服务器时出错
EN

Stack Overflow用户
提问于 2014-01-11 21:27:44
回答 1查看 560关注 0票数 0

嘿,伙计们,我们在工作中有一个私人电子邮件服务器,我需要编写一个电子邮件客户端,以供所有的开发人员使用。我已经让它发送电子邮件没有任何问题,但我似乎不能让它检索电子邮件。根据验证过程,我收到一个错误,指出远程证书无效。我们在电子邮件服务器中使用代理,但他们在我的黑莓上设置了一个外部地址,它100%工作,我可以发送和接收电子邮件,但在这个应用程序中它不会…我搜索谷歌,得到我需要禁用ssl验证证书,我做了,但我仍然得到错误。

代码语言:javascript
运行
复制
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();
        }
    }
}
EN

回答 1

Stack Overflow用户

发布于 2014-01-11 21:46:01

您应该使用接受RemoteCertificateValidationCallback参数的连接重载:

代码语言:javascript
运行
复制
client.Connect("example.com", 995, true, 60000, 60000, 
    new RemoteCertificateValidationCallback(ValidateServerCertificate));

public static bool ValidateServerCertificate(object sender, X509Certificate certificate, X509Chain chain, SslPolicyErrors sslPolicyErrors)
{         
    return true;  // force the validation of any certificate
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/21062805

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档