• 大小: 211KB
    文件类型: .rar
    金币: 2
    下载: 0 次
    发布日期: 2024-02-03
  • 语言: 其他
  • 标签: smtp  email  username  file  

资源简介

smtp 发送邮件给多个用户,带附件,测试本机smtp服务是否正常.附带 excel导出报表,在发送邮件

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Microsoft.Office.Interop.Owc11;
using System.Net.Mail;

namespace mailtest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        // 创建附件
        private void btnInclude_Click(object sender EventArgs e)
        {
            // 创建excel路径
            string path = Application.StartupPath.ToString();
            // 实例化execl中的一张表            
            Microsoft.Office.Interop.Owc11.SpreadsheetClass xlsheet = new Microsoft.Office.Interop.Owc11.SpreadsheetClass();
            xlsheet.ActiveSheet.Cells[1 1] = “这是一个测试用的excel“;
            // 列宽自适应
            xlsheet.Cells.EntireColumn.AutoFit();
            // 设置路径和名称
            string strTime = DateTime.Now.Year.ToString() + DateTime.Now.Month.ToString() + DateTime.Now.Day.ToString() +
                             DateTime.Now.Hour.ToString() + DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString() +
                             DateTime.Now.Millisecond.ToString();
            path += “\\“ + strTime + “.xls“;
            // 导出excel表格
            xlsheet.Export(path Microsoft.Office.Interop.Owc11.SheetExportActionEnum.ssExportActionNone Microsoft.Office.Interop.Owc11.SheetExportFormat.ssExportxmlSpreadsheet);
            this.tbxInclude.Text = path;
        }

        // 发送邮件
        private void btnSend_Click(object sender EventArgs e)
        {
            bool flg = true;
            string msg = ““;
            // 输入判断
            if (this.tbxName.Text == ““)
            {
                flg = false;
                msg = “用户名不能为空“;
                this.tbxName.Focus();
            }
            else if (this.tbxPassWord.Text == ““)
            {
                flg = false;
                msg = “密码不能为空“;
                this.tbxPassWord.Focus();
            }
            else if (this.tbxPassWord.Text == ““)
            {
                flg = false;
                msg = “密码不能为空“;
                this.tbxPassWord.Focus();
            }
            else if (this.tbxSMTP.Text == ““)
            {
                flg = false;
                msg = “SMTP不能为空“;
                this.tbxSMTP.Focus();
            }
            else if (this.tbxPort.Text == ““)
            {
                flg = false;
                msg = “端口号不能为空“;
                this.tbxPort.Focus();
            }
            else if (this.tbxSendAddress.Text == ““)
            {
                flg = false;
                msg = “发送地址不能为空“;
                this.tbxSendAddress.Focus();
            }
            else if (this.tbxGetAddress.Text == ““)
            {
                flg = false;
                msg = “收件人地址不能为空“;
                this.tbxGetAddress.Focus

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       5448  2010-09-15 10:39  mailtest.csproj

     文件        500  2010-09-15 08:48  Program.cs

     文件      15872  2010-09-15 10:53  bin\Debug\mailtest.exe

     文件        117  2010-09-15 10:26  bin\Debug\mailtest.exe.config

     文件        117  2010-09-15 10:26  bin\Debug\mailtest.vshost.exe.config

     文件        490  2010-03-17 22:39  bin\Debug\mailtest.vshost.exe.manifest

     文件     141928  2007-10-10 09:48  bin\Debug\Microsoft.Office.Interop.Graph.dll

     文件     223800  2007-10-10 09:48  bin\Debug\office.dll

     文件     141928  2007-10-10 09:48  obj\Microsoft.Office.Interop.Graph.dll

     文件     223800  2007-10-10 09:48  obj\office.dll

     文件       2152  2010-09-15 08:48  obj\x86\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       6705  2010-09-15 14:36  obj\x86\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件        494  2010-09-15 10:51  obj\x86\Debug\GenerateResource-ResGen.read.1.tlog

     文件        510  2010-09-15 10:51  obj\x86\Debug\GenerateResource-ResGen.write.1.tlog

     文件          2  2010-09-15 10:51  obj\x86\Debug\GenerateResource.read.1.tlog

     文件          2  2010-09-15 10:51  obj\x86\Debug\GenerateResource.write.1.tlog

     文件       1391  2010-09-15 14:37  obj\x86\Debug\mailtest.csproj.FileListAbsolute.txt

     文件        944  2010-09-15 14:36  obj\x86\Debug\mailtest.csproj.ResolveComReference.cache

     文件      15872  2010-09-15 10:53  obj\x86\Debug\mailtest.exe

     文件        180  2010-09-15 10:51  obj\x86\Debug\mailtest.Form1.resources

     文件      26112  2010-09-15 10:53  obj\x86\Debug\mailtest.pdb

     文件        180  2010-09-15 10:39  obj\x86\Debug\mailtest.Properties.Resources.resources

     文件       4608  2010-09-15 10:50  obj\x86\Debug\TempPE\Properties.Resources.Designer.cs.dll

     文件       1452  2010-09-15 08:48  Properties\AssemblyInfo.cs

     文件       2840  2010-09-15 10:26  Properties\Resources.Designer.cs

     文件       5612  2010-09-15 08:48  Properties\Resources.resx

     文件       1087  2010-09-15 10:26  Properties\Settings.Designer.cs

     文件        249  2010-09-15 08:48  Properties\Settings.settings

     文件        117  2010-09-15 10:26  app.config

     文件       5956  2010-09-15 10:55  Form1.cs

............此处省略12个文件信息

评论

共有 条评论