如何在移动设备上使用C#从pop3 + ssl服务器接收邮件. [英] How to receive mail from pop3+ssl server with C# on mobile.

查看:78
本文介绍了如何在移动设备上使用C#从pop3 + ssl服务器接收邮件.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好!

我可以使用.Net 2.0中的SslStream从窗口应用程序中的pop3 + ssl服务器接收邮件.
但是在.Net CF中,它不支持SslStream.因此,我应该使用哪个对象来连接pop3 + ssl服务器.
我想自己写.我知道我必须使用TCPClient或Socket,NetworkStream,StreamReader和X509Certificates,但是我不知道如何使用X509Certificates与服务器进行身份验证.
如果有关于pop3 + ssl的任何示例,请为我分享.

谢谢和最好的问候,

LuongHVM:)

Hi all!

I can receive mail from pop3+ssl server in window application with SslStream in .Net 2.0.
But in .Net CF, it doesn''t support SslStream. So, which object i should to use to connect pop3+ssl server.
I want to write it by myself. I know i have to use TCPClient or Socket, NetworkStream, StreamReader, and X509Certificates but i don''t know how to use X509Certificates to authenticate with server.
If have any example about pop3+ssl, pls share for me.

Thanks and Best Regards,

LuongHVM :)

推荐答案

大家好!

经过研究,我已经解决了.有关更多详细信息,请参见:)
实现安全套接字

读完我的代码:)
Hi all!

After research, i have solved it. See it for more details :)
Implementing a Secure Socket

My code after read it :)
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Net.Sockets;
using System.Net;
using System.IO;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using System.Security.Cryptography.X509Certificates;
namespace SslTest
{
    public partial class Form1 : Form
    {
        
        private const ushort SO_SECURE = 0x2001;
        private const ushort SO_SEC_SSL = 0x2004;
        private const int _SO_SSL_VALIDATE_CERT_HOOK = 0x08;
        private const int SO_SSL_FAMILY = 0x00730000;
        private const long _SO_SSL = ((2L << 27) | SO_SSL_FAMILY);
        private const uint IOC_IN = 0x80000000;
        private const long SO_SSL_SET_VALIDATE_CERT_HOOK = (IOC_IN | _SO_SSL | _SO_SSL_VALIDATE_CERT_HOOK);
        public delegate int SSLVALIDATECERTFUNC(uint dwType, IntPtr pvArg, uint dwChainLen, IntPtr pCertChain, uint dwFlags);
        private IntPtr hookFunc;
        public Form1()
        {
            InitializeComponent();
        }
        private void btnReceive_Click(object sender, EventArgs e)
        {
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            
            socket.SetSocketOption(SocketOptionLevel.Socket, (SocketOptionName)SO_SECURE, SO_SEC_SSL);
            hookFunc = Marshal.GetFunctionPointerForDelegate(new SSLVALIDATECERTFUNC(ValidateCert));

            byte[] inBuffer = new byte[8];
            byte[] hookFuncBytes = BitConverter.GetBytes(hookFunc.ToInt32());
            Array.Copy(hookFuncBytes, inBuffer, hookFuncBytes.Length);
            unchecked
            {
                socket.IOControl((int)SO_SSL_SET_VALIDATE_CERT_HOOK, inBuffer, null);
            }
            
            IPHostEntry hostEntry = Dns.GetHostEntry("xxx.xxx.xxx.xxx");
            IPEndPoint ip = new IPEndPoint(hostEntry.AddressList[0], 995);
            socket.Connect(ip);
            NetworkStream netStream = new NetworkStream(socket);
            StreamReader reader = new StreamReader(netStream);
            MessageBox.Show(reader.ReadLine());
            netStream.Close();
            reader.Close();
            
            socket.Shutdown(SocketShutdown.Both);
            socket.Close();
        }
        private int ValidateCert(uint dwType, IntPtr pvArg, uint dwChainLen, IntPtr pCertChain, uint dwFlags)
        {
            return 0;
        }
    }
}



希望能帮助到某人! ;)

最好的问候,


LuongHVM



Hope to help someone! ;)

Best Regards,


LuongHVM


您好,您的解决方案对我有很大帮助.但是我无法将其与我的代码集成.您可以分享与此相关的电子邮件获取方式吗?
Hi, your solution helped me a lot. But i can not integrate it with my code. Can you share how to get email with this?


这篇关于如何在移动设备上使用C#从pop3 + ssl服务器接收邮件.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆