0

皆さん、私たちは仕事でプライベートな電子メール サーバーを持っており、すべての開発者が使用する電子メール クライアントを作成する必要があります。問題なくメールを送信できましたが、メールを取得できないようです。検証手順に従って、リモート証明書が無効であるというエラーが表示されます。私たちはメールサーバーでプロキシを使用していますが、彼らは私のブラックベリーに外部アドレスを設定しています.100%動作します.メールを送受信できますが、このアプリケーションでは動作しません... Googleを検索したところ、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();
        }
    }
}
4

1 に答える 1

0

RemoteCertificateValidationCallback パラメータを受け入れる Connect オーバーロードを使用する必要があります。

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
}
于 2014-01-11T13:46:00.967 に答える