基本信息
源码名称:C#邮箱发送(winform+源码)
源码大小:0.18M
文件格式:.rar
开发语言:C#
更新时间:2021-04-12
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

开发工具 Visual Studio 2017 无需数据库,可直接使用源码。 

       注意:发送人QQ邮箱密码输入授权码,获取邮箱授权码超简单自行百度。


    try
            {
                //确定smtp服务器地址。实例化一个Smtp客户端
                System.Net.Mail.SmtpClient client = new System.Net.Mail.SmtpClient(cmbBoxSMTP.Text);
                //生成一个发送地址
                string strFrom = txtUserName.Text "@qq.com";

                //构造一个发件人姓名信息
                MailAddress from = new MailAddress(strFrom, txtDisplayName.Text, Encoding.UTF8);
                //构造一个收件人地址对象
                MailAddress to = new MailAddress(txtEmail.Text, txtToName.Text, Encoding.UTF8);

                //构造一个Email的Message对象
                MailMessage message = new MailMessage(from, to);

                //为 message 添加附件
                foreach (TreeNode treeNode in treeViewFileList.Nodes)
                {
                    //得到文件名
                    string fileName = treeNode.Text;
                    //判断文件是否存在
                    if (File.Exists(fileName))
                    {
                        //构造一个附件对象
                        Attachment attach = new Attachment(fileName);
                        //得到文件的信息
                        ContentDisposition disposition = attach.ContentDisposition;
                        disposition.CreationDate = System.IO.File.GetCreationTime(fileName);
                        disposition.ModificationDate = System.IO.File.GetLastWriteTime(fileName);
                        disposition.ReadDate = System.IO.File.GetLastAccessTime(fileName);
                        //向邮件添加附件
                        message.Attachments.Add(attach);
                    }
                    else
                    {
                        MessageBox.Show("文件" fileName "未找到!");
                    }
                }

                //添加邮件主题和内容
                message.Subject = txtSubject.Text DateTime.Now;
                message.SubjectEncoding = Encoding.UTF8;
                message.Body = rtxtBody.Text;
                message.BodyEncoding = Encoding.UTF8;

                //设置邮件的信息
                client.DeliveryMethod = SmtpDeliveryMethod.Network;
                message.BodyEncoding = Encoding.UTF8;
                message.IsBodyHtml = false;

                //如果服务器支持安全连接,则将安全连接设为true。
                client.EnableSsl = true;

                //设置用户名和密码。
                //string userState = message.Subject;
                client.UseDefaultCredentials = false;
                string username = txtUserName.Text;
                string passwd = txtPassword.Text;
                //用户登陆信息
                NetworkCredential myCredentials = new NetworkCredential(username, passwd);
                client.Credentials = myCredentials;
                //发送邮件
                client.Send(message);
                //提示发送成功
                MessageBox.Show("发送成功!");
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }