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

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

本次赞助数额为: 2 元 
   源码介绍
无论是qq邮箱发信,还是网易163邮箱发信,发件箱需要开启smtp 才可以发邮件的

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WinHtmlEditor;

namespace WinFormForSendMail
{
    public partial class FromSendMail : Form
    {
        public FromSendMail()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FromSendMail_Load(object sender, EventArgs e)
        {
            //初始化邮箱服务器
            Dictionary<string, int> dicList = new Dictionary<string, int>();
            dicList.Add("smtp.qq.com", 25);
            dicList.Add("smtp.163.com", 25);
            dicList.Add("smtp.mail.yahoo.com", 25);
            dicList.Add("smtp.126.com", 25);
            dicList.Add("smtp.sina.com", 25);
            dicList.Add("smtp.sohu.com", 25);
            dicList.Add("smtp.gmail.com", 25);
            foreach (var item in dicList)
            {
                ddlList.Items.Add(item.Key);
            }
            ddlList.SelectedIndex = 0;

            //初始化皮肤
            skinEngine1.SkinFile = "Skins\\PageColor2.ssk";
            skinEngine1.AddForm(this);

            this.htmlEditor1.BodyInnerHTML = "";
            this.htmlEditor1.FontName = new FontFamily("Arial");
            this.htmlEditor1.FontSize = FontSize.Seven;
        }
        /// <summary>
        /// 发送
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSend_Click(object sender, EventArgs e)
        {

            if (txtSendUser.Text.Trim().Length==0||txtSendUserPwd.Text.Trim().Length==0)
            {
                MessageBox.Show("发件人和密码不能为空!"); return;
            }
            if (txtRecvierUser.Text.Trim().Length==0||txtTitle.Text.Trim().Length==0)
            {
                 MessageBox.Show("收件人和标题不能为空!"); return;
            }
            bool flag = MailHelper.SendMail(txtSendUser.Text, txtSendUser.Text, txtSendUser.Text, txtSendUserPwd.Text, txtTitle.Text, htmlEditor1.BodyInnerHTML, txtRecvierUser.Text, openFileDialog1, ddlList.Text, txtFile);
            if (flag)
            {
                MessageBox.Show("发送成功!");
            }
            else
            {
                MessageBox.Show("发送失败!");
            }
        }
        /// <summary>
        /// 选择文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnFile_Click(object sender, EventArgs e)
        {
            OpenFileDialog openFileDialog1 = new OpenFileDialog();
            openFileDialog1.InitialDirectory = "D:\\Patch";//对话框初始目录
            openFileDialog1.Filter = "All files (*.*)|";
            openFileDialog1.FilterIndex = 2;
            openFileDialog1.RestoreDirectory = true;
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
                txtFile.Text = openFileDialog1.FileName;
        }

        private void btnWeb_Click(object sender, EventArgs e)
        {
            WebBro web = new WebBro();
            web.ShowDialog();
        }
    }
}