qunFa.aspx文件的代码:

<%...@ Page language="c#" Codebehind="qunFa.aspx.cs" AutoEventWireup="false" Inherits="liuwei.hanmail.qunFa" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
  <HEAD>
        <title>qunFa</title>
<meta content="Microsoft Visual Studio .NET 7.1" name=GENERATOR>
<meta content=C# name=CODE_LANGUAGE>
<meta content=JavaScript name=vs_defaultClientScript>
<meta content=http://schemas.microsoft.com/intellisense/ie5 name=vs_targetSchema>
  </HEAD>
<body MS_POSITIONING="GridLayout">
<form id=Form1 method=post runat="server">
            <asp:ListBox id="ListBoxMsg" style="Z-INDEX: 118; LEFT: 136px; POSITION: absolute; TOP: 344px"
                runat="server" Width="440px" Height="184px"></asp:ListBox>
            <asp:Label id="Label11" style="Z-INDEX: 108; LEFT: 120px; POSITION: absolute; TOP: 320px" runat="server">信息查看</asp:Label>
            <asp:Label id="Label10" style="Z-INDEX: 117; LEFT: 112px; POSITION: absolute; TOP: 16px" runat="server">SMTP服务器地址</asp:Label>
            <asp:Label id="Label9" style="Z-INDEX: 100; LEFT: 128px; POSITION: absolute; TOP: 48px" runat="server">用户名</asp:Label>
            <asp:TextBox id="TextBoxSrv" style="Z-INDEX: 101; LEFT: 264px; POSITION: absolute; TOP: 24px"
                runat="server" Width="240px"></asp:TextBox>
            <asp:Label id="Label8" style="Z-INDEX: 102; LEFT: 360px; POSITION: absolute; TOP: 48px" runat="server">口令</asp:Label>
            <asp:TextBox id="TextBoxUser" style="Z-INDEX: 103; LEFT: 192px; POSITION: absolute; TOP: 48px"
                runat="server" Width="152px"></asp:TextBox>
            <asp:TextBox id="TextBoxPwd" style="Z-INDEX: 104; LEFT: 416px; POSITION: absolute; TOP: 48px"
                runat="server" Width="168px" TextMode="Password"></asp:TextBox>
            <asp:Label id="Label4" style="Z-INDEX: 105; LEFT: 128px; POSITION: absolute; TOP: 80px" runat="server">发信人</asp:Label>
            <asp:Label id="Label5" style="Z-INDEX: 106; LEFT: 360px; POSITION: absolute; TOP: 80px" runat="server">收信人</asp:Label>
            <asp:TextBox id="TextBoxSend" style="Z-INDEX: 107; LEFT: 192px; POSITION: absolute; TOP: 80px"
                runat="server"></asp:TextBox>
            <asp:TextBox id="TextBoxRev" style="Z-INDEX: 109; LEFT: 416px; POSITION: absolute; TOP: 80px"
                runat="server" Width="168px"></asp:TextBox>
            <asp:Label id="Label6" style="Z-INDEX: 110; LEFT: 128px; POSITION: absolute; TOP: 112px" runat="server">主题</asp:Label>
            <asp:TextBox id="TextBoxSubject" style="Z-INDEX: 112; LEFT: 192px; POSITION: absolute; TOP: 104px"
                runat="server" Width="392px"></asp:TextBox>
            <asp:TextBox id="TextBoxMailText" style="Z-INDEX: 113; LEFT: 144px; POSITION: absolute; TOP: 160px"
                runat="server" Width="440px" TextMode="MultiLine" Height="120px"></asp:TextBox>
            <asp:Label id="Label7" style="Z-INDEX: 114; LEFT: 128px; POSITION: absolute; TOP: 136px" runat="server">邮件内容</asp:Label>
            <asp:Button id="ButtonSend" style="Z-INDEX: 115; LEFT: 464px; POSITION: absolute; TOP: 296px"
                runat="server" Text="发送"></asp:Button>
            <asp:Label id="LabelErr" style="Z-INDEX: 116; LEFT: 696px; POSITION: absolute; TOP: 136px"
                runat="server"></asp:Label></FORM>
    </body>
</HTML>

qunFa.aspx.cs的代码:

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;
using System.Net;
using System.Net.Sockets;

namespace Sendmail
...{
    /**//// <summary>
    /// qunFa 的摘要说明。
    /// </summary>
    public class qunFa : System.Web.UI.Page
    ...{
        protected System.Web.UI.WebControls.Label LabelErr;
        protected System.Web.UI.WebControls.Button ButtonSend;
        protected System.Web.UI.WebControls.Label Label7;
        protected System.Web.UI.WebControls.TextBox TextBoxMailText;
        protected System.Web.UI.WebControls.TextBox TextBoxSubject;
        protected System.Web.UI.WebControls.Label Label6;
        protected System.Web.UI.WebControls.TextBox TextBoxRev;
        protected System.Web.UI.WebControls.TextBox TextBoxSend;
        protected System.Web.UI.WebControls.Label Label5;
        protected System.Web.UI.WebControls.Label Label4;
        protected System.Web.UI.WebControls.TextBox TextBoxPwd;
        protected System.Web.UI.WebControls.TextBox TextBoxUser;
        protected System.Web.UI.WebControls.Label Label8;
        protected System.Web.UI.WebControls.TextBox TextBoxSrv;
        protected System.Web.UI.WebControls.Label Label9;
        protected System.Web.UI.WebControls.Label Label11;
        protected System.Web.UI.WebControls.ListBox ListBoxMsg;
        protected System.Web.UI.WebControls.Label Label10;

        TcpClient smtpSrv;
        NetworkStream netStrm;
        string CRLF=" ";
    
        private void Page_Load(object sender, System.EventArgs e)
        ...{
        }

        Web 窗体设计器生成的代码#region Web 窗体设计器生成的代码
        override protected void OnInit(EventArgs e)
        ...{
            //
            // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
            //
            InitializeComponent();
            base.OnInit(e);
        }
        
        /**//// <summary>
        /// 设计器支持所需的方法 - 不要使用代码编辑器修改
        /// 此方法的内容。
        /// </summary>
        private void InitializeComponent()
        ...{    
            this.ButtonSend.Click += new System.EventHandler(this.ButtonSend_Click);
            this.Load += new System.EventHandler(this.Page_Load);

        }
        #endregion


        private void ButtonSend_Click(object sender, System.EventArgs e)
        ...{
            this.ListBoxMsg.Items.Clear();
            string[] userList=this.TextBoxRev.Text.Split(',');
            for(int i=0;i<userList.Length;i++)
                Qun(userList[i]);
            

        }

        public void Qun(string userList)
        ...{
            try
            ...{
                string data;
                smtpSrv=new TcpClient(this.TextBoxSrv.Text,25);                
                netStrm=smtpSrv.GetStream();
                StreamReader rdStrm=new StreamReader(smtpSrv.GetStream());
                this.WriteStream("EHLO Local");
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                this.WriteStream("AUTH LOGIN");
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                data=this.TextBoxUser.Text;
                data=AuthStream(data);
                this.WriteStream(data);
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                data=this.TextBoxPwd.Text;
                data=AuthStream(data);
                this.WriteStream(data);
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                data="MAIL FROM:<"+this.TextBoxSend.Text+">";
                this.WriteStream(data);
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                data="RCPT TO:<"+userList+">";
                this.WriteStream(data);
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                this.WriteStream("DATA");
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                data="Date:"+DateTime.Now;
                this.WriteStream(data);
                data="From:"+this.TextBoxSend.Text;
                this.WriteStream(data);            
                data="TO:"+userList;
                this.WriteStream(data);
                data="SUBJECT:"+this.TextBoxSubject.Text;
                this.WriteStream(data);
                data="Reply-TO:"+this.TextBoxSend.Text;
                this.WriteStream(data);
                this.WriteStream("");
                this.WriteStream(this.TextBoxMailText.Text);
                this.WriteStream(".");
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                this.WriteStream("QUIT");
                this.ListBoxMsg.Items.Add(rdStrm.ReadLine());
                netStrm.Close();
                rdStrm.Close();
                this.LabelErr.Text="发送成功!";
            }
            catch(Exception ex)
            ...{
                this.LabelErr.Text=ex.ToString();
            }
        }
        private void WriteStream(string strCmd)
        ...{
            strCmd+=CRLF;
            byte[] bw=System.Text.Encoding.Default.GetBytes(strCmd);
            netStrm.Write(bw,0,bw.Length);
        }

        private string AuthStream(string strCmd)
        ...{
            try
            ...{
                byte[] by=System.Text.Encoding.Default.GetBytes(strCmd);
                strCmd=Convert.ToBase64String(by);
            }
            catch(Exception err)
            ...{
                return err.ToString();
            }
            return strCmd;
        }
    }
}

注:多个收件人之间用逗号隔开

用Socket发邮件的代码(可以群发)相关推荐

  1. php发送邮件smtp源码,php下使用SMTP发邮件的代码

    首页 > 网络编程 > PHP编程 > php技巧 > php下使用SMTP发邮件的代码 php下使用SMTP发邮件的代码 2008-01-10 20:37:22 作者: ph ...

  2. java发邮件的代码

    通过java发送邮件的代码 转载请注明出处:java发邮件的代码 package com.zuidaima.util.mail;import java.util.Properties;import j ...

  3. python自动批量发邮件脚本_批量群发,营销必备!Python代码实现自动发送邮件!...

    在运维开发中,使用 Python 发送邮件是一个非常常见的应用场景.今天一起来探讨一下,GitHub 的大牛门是如何使用 Python 封装发送邮件代码的. 一般发邮件方法SRE实战 互联网时代守护先 ...

  4. SpringBoot-Mail 发邮件(单发、群发、加附件、HTML格式)

    我们处理异常通常会写入日志,但我们无法及时知道.如果能够将异常信息发送到邮箱,我们可以在第一时间发现这个异常.除此以外,还可以用来给用户发验证码以及各种离线消息等等. 说明:本Demo是用Spring ...

  5. php 操作 腾讯企业邮箱设置发邮件,纯代码实现WordPress使用腾讯企业邮箱发送邮件...

    为什么选择腾讯企业邮箱,其中有个非常优秀的功能,就是可以绑定在腾讯云购买的域名为邮箱的域名,这样子看起来邮箱会更加的正统一点.另一个就是可以直接绑定到QQ邮箱,相对来说平时读邮件的时候回显得更加方便. ...

  6. python发邮件给女朋友代码_python发邮件的代码

    # -*- coding: utf-8 -*- # ================================================= # # 描述:    KEmail 发送邮件类 ...

  7. 一段.net 发邮件的代码

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.N ...

  8. 方便他人快速给你发邮件简单代码实现 QQ邮箱一键邮我组件让你体验什么是快?

    "邮我"组件可以生成"给我写信"的快捷方式,可放置于您的网站或博客上,作为反馈邮箱.除了比文字链接更美观外,"邮我"组件还可以避免邮箱地址泄 ...

  9. Php邮件通知源码,php发邮件源码

    夜影驱动编程小编今天和大家分享一份PHP 留言以及邮件发送源码如图有懂的 速速回答 赏金多多 现在发送邮件不再像过去mail函数那么简单,单纯留言很简单,文本也好,数据库也好都能轻易实现,发邮件稍微复 ...

最新文章

  1. UVA 1471 Defense Lines 防线 (LIS变形)
  2. Python Numpy学习手册(翻译自斯坦福大学 CS231n: Convolutional Neural Networks for Visual Recognition)
  3. python常用库 自动化办公类 —— PyPDF2(处理pdf文件)
  4. sqlserver 分页_四类数据库分页实现方案总结之PG分页实现
  5. 总结之前做项目中要注意的一些书写规范
  6. pip 更改源   pip加速
  7. Spark 性能相关参数配置详解-任务调度篇
  8. 某厂面试归来,发现自己落伍了!
  9. IntelliJ IDEA 设置Output (输出窗口)窗口字体大小
  10. 我所理解的领域驱动模型设计
  11. vue安装jsencrypt_vue使用JSEncrypt实现rsa加密及挂载方法
  12. SQLi-LABS Less-2,联合注入+报错注入
  13. 线性代数之——复数矩阵
  14. 休息休闲推荐 ---- 电视剧《觉醒年代》百年优秀历史纪录电视剧
  15. 为什么宝宝做错事被骂哭后,还要求抱抱?
  16. 怎样用计算机截图,如何在电脑中截图
  17. SpringCloud—07—高级之SpringCloud Alibaba上
  18. 无法将您的Kindle连接到Wi-Fi网络怎么办-kindle无法连接wifi-kindle无法连接手机热点
  19. 外文翻译原文附在后面_外文翻译及外文原文(参考格式).doc
  20. 小米重要通知android,Android开发笔记——小米通知‘坑’ app的通知一直显示在不重要通知里 ......

热门文章

  1. oracle中显示周,oracle中得到一段时间内天,月,周列表
  2. Vue开发使用Axios遇到了大坑!
  3. PCL:官方程序 Region growing segmentation
  4. 数据结构与算法(8-2)有序表查找(折半查找(二分查找)、插值查找)
  5. matlab中调用java代码_Matlab中调用第三方Java代码
  6. js去el的map_转:el表达式获取map对象的内容 js中使用el表达式 js 中使用jstl 实现 session.removeattribute...
  7. 如何理解numpy.nan_to_num
  8. Blender纹理基础学习视频教程 CGCookie – Fundamentals of Texturing in Blender
  9. 基于S3C4510B的一个简单BSP的开发报告
  10. 二分法:二分查找(递归+非递归)实现