| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 4455 人关注过本帖, 2 人收藏
标题:求一邮件系统的源代码
只看楼主 加入收藏
scindy
Rank: 1
等 级:新手上路
威 望:1
帖 子:591
专家分:4
注 册:2006-10-23
结帖率:50%
收藏(2)
 问题点数:0 回复次数:8 
求一邮件系统的源代码
如题目,从网上找了一些,都感觉不太好用,

请问谁有.NET的源码啊?

小弟先在这谢谢大家了~~
搜索更多相关主题的帖子: 源代码 邮件 系统 NET 源码 
2007-11-24 20:42
FenteLi
Rank: 1
来 自:上海
等 级:新手上路
帖 子:124
专家分:0
注 册:2007-11-24
收藏
得分:0 
这个程序是我自己写的,是通过Soket进行连接的,由于时间仓促所以只写了发送邮件;源程序如下,在这里我只转载了源代码:
using System;
using System.Collections.Generic;
using System.Text;
using
using
using

namespace FTPTest
{
    class MailNotice
    {
        ////////////////////////////////////////////////////////////////////////////////////////////
        //类名:        SendMail
        //功能:        主要实现了邮件的发送功能,是通过SMTP协议实现的
        //基本需求:    需要IO,Net,Net.Sockets命名空间的支持;
        //说明:        邮件发送的内容是固定的,硬编码在了代码中,可根据需要自动修改
        //来源:        [url]http://www.[/url]    学习.NET的殿堂
        ////////////////////////////////////////////////////////////////////////////////////////////
        private IPAddress IPAdd;
        private IPEndPoint IPep;
        private TcpClient client;
        private NetworkStream stream;
        public MailNotice()
        {
            IPAdd = Dns.GetHostEntry("smtp.).AddressList[0];
            IPep = new IPEndPoint(IPAdd, 25);
            client = new TcpClient();
            try
            {
                client.Connect(IPep);
            }
            catch (Exception ep)
            {
                throw new IOException("邮件服务器连接失败:" + ep.Message);
            }
            stream = client.GetStream();
        }
        ~MailNotice()
        {
            if (client.Connected == true)
            {
                client.Close();
            }
        }

        //发送命令
        private void SendCommand(string Command)
        {
            if (stream.CanWrite)
            {
                Byte[] SendByte = Encoding.UTF8.GetBytes(Command);
                try
                {
                    stream.Write(SendByte, 0, SendByte.Length);
                }
                catch (Exception exp)
                {
                    throw new IOException("发送" + Command + "命令出现异常:" + exp.Message);
                }
            }
            else
            {
                throw new IOException("邮件命令发送失败!请检查网络连接。");
            }
        }
        //接受数据
        private string ReceiveEcho()
        {
            if (stream.CanRead)
            {
                Byte[] GetBytes = new Byte[client.ReceiveBufferSize];
                try
                {
                    stream.Read(GetBytes, 0, (int)client.ReceiveBufferSize);
                }
                catch (Exception exp)
                {
                    throw new IOException("接受数据的时候出现了异常:" + exp.Message);
                }
                string Echo = Encoding.UTF8.GetString(GetBytes);
                return Echo;
            }
            else
            {
                throw new IOException("接受数据失败!请检查网络连接。");
            }
        }
        //下面的方法将ascii转换成base64编码
        private string AsciiToBase64(string AsciiMsg)
        {
            byte[] AsciiBytes = new byte[512];
            byte[] Base64Bytes = new byte[512];
            string AsciiMsg1 = null;
            string Base64Msg = null;
            switch (AsciiMsg.Length % 3)
            {
                case 1:
                    {
                        AsciiMsg1 = AsciiMsg + "\0\0";
                        break;
                    }
                case 2:
                    {
                        AsciiMsg1 = AsciiMsg + "\0";
                        break;
                    }
                default:
                    {
                        AsciiMsg1 = AsciiMsg;
                        break;
                    }
            }
            for (int i = 0; i < AsciiMsg1.Length / 3; i++)
            {
                string AsciiMsg2 = AsciiMsg1.Substring(i * 3, 3);
                AsciiBytes = System.Text.Encoding.ASCII.GetBytes(AsciiMsg2);
                System.Security.Cryptography.ToBase64Transform transformer = new System.Security.Cryptography.ToBase64Transform();
                transformer.TransformBlock(AsciiBytes, 0, AsciiBytes.Length, Base64Bytes, 0);
                string str = System.Text.Encoding.ASCII.GetString(Base64Bytes, 0, Base64Bytes.Length);
                str = str.Substring(0, 4);
                Base64Msg += str;
            }
            return Base64Msg;
        }
        //下面函数实现了,邮件的发送。
        public void Send()
        {
            string EmailBody = "";//这里是邮件的内容
            EmailBody += "Hello All,\r\n";
            EmailBody += "http://www.这个是我的主页啊,请多多光顾哦!\r\n";
            string User = "test";//登陆SMTP服务器用户名,比如你自己的邮箱是[email]test@[/email] 密码是test
            string Pass = "test";//登陆密码
            string From = "381616212@发件人地址
            string [] To=new string[2];
            To[0]="381616212@如果有多个收件人,可以这样写
            //To[1] = "dan@收件人地址
            //To[2] = "andy.speed@
            //To[3] = "leopold.li@
            //To[1] = "melinda.xia@
            //To[5] = "leesli@
            string Subject = "FAILURE NOTICE";//邮件的主题
            string Data = EmailBody;//将当前时间作为邮件的正文
            string strCommand = "";
            string Response = "";
            Response = ReceiveEcho();

            //第一次返回信息中如果包含了220就说明服务器连接成功,就可以向服务器发送标识
            if (Response.IndexOf("220") < 0)
            {
                throw new IOException("连接服务器失败:" + Response);
            }
            strCommand = "HELO " + User + "\r\n";
            SendCommand(strCommand);

            //发送标识成功返回信息中就会包含250,发送验证命令
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("250") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            strCommand = "AUTH LOGIN\r\n";
            SendCommand(strCommand);

            //返回信息包含334说明验证命令发送成功,发用户名
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("334") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            strCommand = AsciiToBase64(User) + "\r\n";//用户名和密码必须以base64编码发送
            SendCommand(strCommand);

            //返回信息包含334说明用户名验证成功,发密码
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("334") < 0)
            {
                throw new IOException("用户名" + strCommand + "验证失败!");
            }
            strCommand = AsciiToBase64(Pass) + "\r\n";//用户名和密码必须以base64编码发送
            SendCommand(strCommand);

            //返回信息包含235说明密码验证成功,发发件地址
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("235") < 0)
            {
                throw new IOException("密码" + strCommand + "验证失败!");
            }
            strCommand = "MAIL FROM:<" + From + ">\r\n";
            SendCommand(strCommand);

            //返回信息包含250说明mail命令发送成功,发rcpt
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("250") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            for (int i = 0; i < 1; i++)
            {
                strCommand = "RCPT TO:<" + To[i] + ">\r\n";
                SendCommand(strCommand);

                //返回信息包含250说明rcpt to命令发送成功,发data
                Response = "";
                Response = ReceiveEcho();
                if (Response.IndexOf("250") < 0)
                {
                    throw new IOException("命令" + strCommand + "发送失败!");
                }
            }
            strCommand = "DATA\r\n";
            SendCommand(strCommand);

            //返回信息包含354说明Data命令发送成功,发数据
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("354") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            strCommand = "Subject:" + Subject + "\r\n";
            strCommand += "To:" + To + "\r\n";
            strCommand += "Cc:\r\n\r\n" + Data + "\r\n\r\n.\r\n";
            SendCommand(strCommand);

            //返回信息包含250说明邮件发送成功
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("250") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            Console.WriteLine("恭喜!邮件发送成功!");
        }
    }
}
2007-11-25 22:52
FenteLi
Rank: 1
来 自:上海
等 级:新手上路
帖 子:124
专家分:0
注 册:2007-11-24
收藏
得分:0 
这个程序是我自己写的,是通过Soket进行连接的,由于时间仓促所以只写了发送邮件;源程序如下,在这里我只转载了源代码:
using System;
using System.Collections.Generic;
using System.Text;
using
using
using

namespace FTPTest
{
    class MailNotice
    {
        ////////////////////////////////////////////////////////////////////////////////////////////
        //类名:        SendMail
        //功能:        主要实现了邮件的发送功能,是通过SMTP协议实现的
        //基本需求:    需要IO,Net,Net.Sockets命名空间的支持;
        //说明:        邮件发送的内容是固定的,硬编码在了代码中,可根据需要自动修改
        //来源:        [url]http://www.[/url]    学习.NET的殿堂
        ////////////////////////////////////////////////////////////////////////////////////////////
        private IPAddress IPAdd;
        private IPEndPoint IPep;
        private TcpClient client;
        private NetworkStream stream;
        public MailNotice()
        {
            IPAdd = Dns.GetHostEntry("smtp.).AddressList[0];
            IPep = new IPEndPoint(IPAdd, 25);
            client = new TcpClient();
            try
            {
                client.Connect(IPep);
            }
            catch (Exception ep)
            {
                throw new IOException("邮件服务器连接失败:" + ep.Message);
            }
            stream = client.GetStream();
        }
        ~MailNotice()
        {
            if (client.Connected == true)
            {
                client.Close();
            }
        }

        //发送命令
        private void SendCommand(string Command)
        {
            if (stream.CanWrite)
            {
                Byte[] SendByte = Encoding.UTF8.GetBytes(Command);
                try
                {
                    stream.Write(SendByte, 0, SendByte.Length);
                }
                catch (Exception exp)
                {
                    throw new IOException("发送" + Command + "命令出现异常:" + exp.Message);
                }
            }
            else
            {
                throw new IOException("邮件命令发送失败!请检查网络连接。");
            }
        }
        //接受数据
        private string ReceiveEcho()
        {
            if (stream.CanRead)
            {
                Byte[] GetBytes = new Byte[client.ReceiveBufferSize];
                try
                {
                    stream.Read(GetBytes, 0, (int)client.ReceiveBufferSize);
                }
                catch (Exception exp)
                {
                    throw new IOException("接受数据的时候出现了异常:" + exp.Message);
                }
                string Echo = Encoding.UTF8.GetString(GetBytes);
                return Echo;
            }
            else
            {
                throw new IOException("接受数据失败!请检查网络连接。");
            }
        }
        //下面的方法将ascii转换成base64编码
        private string AsciiToBase64(string AsciiMsg)
        {
            byte[] AsciiBytes = new byte[512];
            byte[] Base64Bytes = new byte[512];
            string AsciiMsg1 = null;
            string Base64Msg = null;
            switch (AsciiMsg.Length % 3)
            {
                case 1:
                    {
                        AsciiMsg1 = AsciiMsg + "\0\0";
                        break;
                    }
                case 2:
                    {
                        AsciiMsg1 = AsciiMsg + "\0";
                        break;
                    }
                default:
                    {
                        AsciiMsg1 = AsciiMsg;
                        break;
                    }
            }
            for (int i = 0; i < AsciiMsg1.Length / 3; i++)
            {
                string AsciiMsg2 = AsciiMsg1.Substring(i * 3, 3);
                AsciiBytes = System.Text.Encoding.ASCII.GetBytes(AsciiMsg2);
                System.Security.Cryptography.ToBase64Transform transformer = new System.Security.Cryptography.ToBase64Transform();
                transformer.TransformBlock(AsciiBytes, 0, AsciiBytes.Length, Base64Bytes, 0);
                string str = System.Text.Encoding.ASCII.GetString(Base64Bytes, 0, Base64Bytes.Length);
                str = str.Substring(0, 4);
                Base64Msg += str;
            }
            return Base64Msg;
        }
        //下面函数实现了,邮件的发送。
        public void Send()
        {
            string EmailBody = "";//这里是邮件的内容
            EmailBody += "Hello All,\r\n";
            EmailBody += "http://www.这个是我的主页啊,请多多光顾哦!\r\n";
            string User = "test";//登陆SMTP服务器用户名,比如你自己的邮箱是[email]test@[/email] 密码是test
            string Pass = "test";//登陆密码
            string From = "381616212@发件人地址
            string [] To=new string[2];
            To[0]="381616212@如果有多个收件人,可以这样写
            //To[1] = "dan@收件人地址
            //To[2] = "andy.speed@
            //To[3] = "leopold.li@
            //To[1] = "melinda.xia@
            //To[5] = "leesli@
            string Subject = "FAILURE NOTICE";//邮件的主题
            string Data = EmailBody;//将当前时间作为邮件的正文
            string strCommand = "";
            string Response = "";
            Response = ReceiveEcho();

            //第一次返回信息中如果包含了220就说明服务器连接成功,就可以向服务器发送标识
            if (Response.IndexOf("220") < 0)
            {
                throw new IOException("连接服务器失败:" + Response);
            }
            strCommand = "HELO " + User + "\r\n";
            SendCommand(strCommand);

            //发送标识成功返回信息中就会包含250,发送验证命令
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("250") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            strCommand = "AUTH LOGIN\r\n";
            SendCommand(strCommand);

            //返回信息包含334说明验证命令发送成功,发用户名
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("334") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            strCommand = AsciiToBase64(User) + "\r\n";//用户名和密码必须以base64编码发送
            SendCommand(strCommand);

            //返回信息包含334说明用户名验证成功,发密码
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("334") < 0)
            {
                throw new IOException("用户名" + strCommand + "验证失败!");
            }
            strCommand = AsciiToBase64(Pass) + "\r\n";//用户名和密码必须以base64编码发送
            SendCommand(strCommand);

            //返回信息包含235说明密码验证成功,发发件地址
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("235") < 0)
            {
                throw new IOException("密码" + strCommand + "验证失败!");
            }
            strCommand = "MAIL FROM:<" + From + ">\r\n";
            SendCommand(strCommand);

            //返回信息包含250说明mail命令发送成功,发rcpt
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("250") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            for (int i = 0; i < 1; i++)
            {
                strCommand = "RCPT TO:<" + To[i] + ">\r\n";
                SendCommand(strCommand);

                //返回信息包含250说明rcpt to命令发送成功,发data
                Response = "";
                Response = ReceiveEcho();
                if (Response.IndexOf("250") < 0)
                {
                    throw new IOException("命令" + strCommand + "发送失败!");
                }
            }
            strCommand = "DATA\r\n";
            SendCommand(strCommand);

            //返回信息包含354说明Data命令发送成功,发数据
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("354") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            strCommand = "Subject:" + Subject + "\r\n";
            strCommand += "To:" + To + "\r\n";
            strCommand += "Cc:\r\n\r\n" + Data + "\r\n\r\n.\r\n";
            SendCommand(strCommand);

            //返回信息包含250说明邮件发送成功
            Response = "";
            Response = ReceiveEcho();
            if (Response.IndexOf("250") < 0)
            {
                throw new IOException("命令" + strCommand + "发送失败!");
            }
            Console.WriteLine("恭喜!邮件发送成功!");
        }
    }
}
2007-11-25 23:00
scindy
Rank: 1
等 级:新手上路
威 望:1
帖 子:591
专家分:4
注 册:2006-10-23
收藏
得分:0 
非常感谢,不知道有没有收邮件的呢?
或是收邮件的原理是什么啊?
从网上也找了一些,不是很明确`~~

淘宝新到货: http://shop36082390. 电脑及配件/杀毒U盘/移动硬盘/减肥产品/切苹果器/剥蒜器/个性烟灰缸/装饰彩灯/雨伞/女包//手机座/极品铁观间茶叶/五层布衣柜/三洋/日立投影机
QQ:410243392 (常用)
2007-11-26 11:08
一水先生
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-11-5
收藏
得分:0 
收藏了!
2007-11-30 17:10
一水先生
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2007-11-5
收藏
得分:0 
收藏在
[url]http://www.[/url]
了,
不知作者同意不?不同意的话可以删除!
2007-11-30 17:20
FenteLi
Rank: 1
来 自:上海
等 级:新手上路
帖 子:124
专家分:0
注 册:2007-11-24
收藏
得分:0 
收邮件时同过pop3协议来实现的,具体的实现过程和发邮件是差不多的,只是所用的协议不同而已。pop3协议很简单的,这个问题楼主可以自己研究一下。
2007-11-30 17:45
scindy
Rank: 1
等 级:新手上路
威 望:1
帖 子:591
专家分:4
注 册:2006-10-23
收藏
得分:0 
还在继续当中
研究了一段时间了,还是不行,接收不了,我想用IMAIL.或JMAIL来做,怎么把IMAIL或JMAIL导入到.NET命名空间里面呢~~

淘宝新到货: http://shop36082390. 电脑及配件/杀毒U盘/移动硬盘/减肥产品/切苹果器/剥蒜器/个性烟灰缸/装饰彩灯/雨伞/女包//手机座/极品铁观间茶叶/五层布衣柜/三洋/日立投影机
QQ:410243392 (常用)
2008-01-16 13:59
foshan
Rank: 1
等 级:新手上路
威 望:2
帖 子:605
专家分:0
注 册:2006-3-1
收藏
得分:0 
能在发邮件是把附件(例如word、excel、rar压缩文件 )也一同发送出去的吗?

我是2.0超级菜鸟,请多多教导!
2008-10-10 09:21
快速回复:求一邮件系统的源代码
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019791 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved