Util/MailHelper.cs

(开头部分) 10KB

这里只显示每个文件的开头 60 行。登录后可以解锁完整代码。

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Mail;
using System.Net.Mime;
using System.Net.Sockets;
using System.Text;

namespace Util
{
    public class MailHelper
    {

        static TcpClient client;
        /// <summary>
        /// 登录POP3服务器
        /// </summary>
        /// <param name="pop3Server">服务器域名</param>
        /// <param name="port">端口</param>
        /// <param name="username">用户名</param>
        /// <param name="password">密码</param>
        public static void Login(string pop3Server,
                    int port,
                    string username,
                    string password)
        {
            client = new TcpClient(pop3Server, port);
            client.ReceiveTimeout = 10000;
            client.SendTimeout = 10000;
            NetworkStream stream = client.GetStream();
            StreamReader reader = new StreamReader(stream);
            if (!CheckError(reader.ReadLine()))
            {
                throw new Exception("连接错误");
            }

            string msg = "USER " + username + "\r\n";
            byte[] msgByts = Encoding.UTF8.GetBytes(msg);
            stream.Write(msgByts, 0, msgByts.Length);
            if (!CheckError(reader.ReadLine()))
            {
                throw new Exception("用户名错误");
            }

            msg = "PASS " + password + "\r\n";
            msgByts = Encoding.UTF8.GetBytes(msg);
            stream.Write(msgByts, 0, msgByts.Length);
            if (!CheckError(reader.ReadLine()))
            {
                throw new Exception("密码错误");
            }
        }
        /// <summary>
        /// 检查服务器的响应是否有错误
        /// </summary>
        /// <param name="reply">服务器响应</param>
        /// <returns>正确响应返回true;否则返回false</returns>
        private static bool CheckError(string reply)
        {
后面还有 203 行代码,解锁后查看完整代码

24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明

AI 解读

登录后可用,每次 10 积分,解读结果公开显示在下面。

还没有人解读过这个文件。