- 浏览: 117124 次
- 性别:
- 来自: 深圳
文章分类
最新评论
C#批量发送邮件程序
Form1.cs
//c#批量发送邮件程序.远程抓取网页源代码,作为邮件内容.首先批量从文本文件中读取客户邮件地址,然后发送
安装network平台,,添加引用 System.Web.Dll
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.IO;
using System.Web.Mail;
using System.Net;
using System.Text;
namespace WebMail
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.ListBox listBox1;
private System.Windows.Forms.ListBox listBox2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Label label4;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.Label label5;
private System.Windows.Forms.TextBox textBox4;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Label label6;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.TextBox textBox5;
private System.Windows.Forms.Button button5;
private System.Windows.Forms.Label label7;
private System.Windows.Forms.Label label8;
private System.Windows.Forms.TextBox textBox6;
private System.Windows.Forms.TextBox textBox7;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.listBox1 = new System.Windows.Forms.ListBox();
this.listBox2 = new System.Windows.Forms.ListBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.label3 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label4 = new System.Windows.Forms.Label();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.label5 = new System.Windows.Forms.Label();
this.textBox4 = new System.Windows.Forms.TextBox();
this.button3 = new System.Windows.Forms.Button();
this.label6 = new System.Windows.Forms.Label();
this.button4 = new System.Windows.Forms.Button();
this.textBox5 = new System.Windows.Forms.TextBox();
this.button5 = new System.Windows.Forms.Button();
this.label7 = new System.Windows.Forms.Label();
this.label8 = new System.Windows.Forms.Label();
this.textBox6 = new System.Windows.Forms.TextBox();
this.textBox7 = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem3,
this.menuItem4});
this.menuItem1.Text = "文件";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "检测数据库邮件地址文件";
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "检测文本邮件地址文件";
this.menuItem3.Click += new System.EventHandler(this.menuItem3_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "退出程序";
this.menuItem4.Click += new System.EventHandler(this.menuItem4_Click);
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 72);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(96, 16);
this.label1.TabIndex = 0;
this.label1.Text = "目标邮件地址列表";
//
// label2
//
this.label2.Location = new System.Drawing.Point(336, 72);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(120, 16);
this.label2.TabIndex = 1;
this.label2.Text = "邮件发送成功列表";
//
// listBox1
//
this.listBox1.HorizontalScrollbar = true;
this.listBox1.ItemHeight = 12;
this.listBox1.Location = new System.Drawing.Point(16, 104);
this.listBox1.Name = "listBox1";
this.listBox1.Size = new System.Drawing.Size(168, 196);
this.listBox1.TabIndex = 2;
//
// listBox2
//
this.listBox2.HorizontalScrollbar = true;
this.listBox2.ItemHeight = 12;
this.listBox2.Location = new System.Drawing.Point(464, 104);
this.listBox2.Name = "listBox2";
this.listBox2.Size = new System.Drawing.Size(168, 196);
this.listBox2.TabIndex = 3;
//
// button1
//
this.button1.Location = new System.Drawing.Point(208, 104);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(104, 32);
this.button1.TabIndex = 4;
this.button1.Text = "获取邮件地址";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.Location = new System.Drawing.Point(336, 152);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(104, 32);
this.button2.TabIndex = 5;
this.button2.Text = "发送促销邮件";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 16);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(104, 16);
this.label3.TabIndex = 6;
this.label3.Text = "邮件列表文件地址";
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(144, 8);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(400, 21);
this.textBox1.TabIndex = 7;
this.textBox1.Text = "";
//
// label4
//
this.label4.Location = new System.Drawing.Point(24, 312);
this.label4.Name = "label4";
this.label4.Size = new System.Drawing.Size(96, 24);
this.label4.TabIndex = 8;
this.label4.Text = "邮件标题:";
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(152, 312);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(352, 21);
this.textBox2.TabIndex = 9;
this.textBox2.Text = "这里填写各语种邮件标题";
//
// textBox3
//
this.textBox3.BackColor = System.Drawing.SystemColors.Info;
this.textBox3.Location = new System.Drawing.Point(24, 344);
this.textBox3.Multiline = true;
this.textBox3.Name = "textBox3";
this.textBox3.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.textBox3.Size = new System.Drawing.Size(480, 152);
this.textBox3.TabIndex = 10;
this.textBox3.Text = "这里填写邮件内容";
//
// label5
//
this.label5.Location = new System.Drawing.Point(16, 40);
this.label5.Name = "label5";
this.label5.Size = new System.Drawing.Size(96, 16);
this.label5.TabIndex = 11;
this.label5.Text = "HTML文件地址";
//
// textBox4
//
this.textBox4.Location = new System.Drawing.Point(144, 40);
this.textBox4.Name = "textBox4";
this.textBox4.Size = new System.Drawing.Size(400, 21);
this.textBox4.TabIndex = 12;
this.textBox4.Text = "http://www.gamesavor.com/promotion/gamesavorEP0003_english.html";
//
// button3
//
this.button3.Location = new System.Drawing.Point(336, 104);
this.button3.Name = "button3";
this.button3.Size = new System.Drawing.Size(104, 32);
this.button3.TabIndex = 13;
this.button3.Text = "获取网页代码";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// label6
//
this.label6.Location = new System.Drawing.Point(24, 512);
this.label6.Name = "label6";
this.label6.Size = new System.Drawing.Size(96, 24);
this.label6.TabIndex = 14;
this.label6.Text = "邮件内容长度";
//
// button4
//
this.button4.Location = new System.Drawing.Point(392, 512);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(96, 24);
this.button4.TabIndex = 15;
this.button4.Text = "计算邮件长度";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// textBox5
//
this.textBox5.Location = new System.Drawing.Point(136, 512);
this.textBox5.Name = "textBox5";
this.textBox5.TabIndex = 16;
this.textBox5.Text = "0";
//
// button5
//
this.button5.Location = new System.Drawing.Point(208, 152);
this.button5.Name = "button5";
this.button5.Size = new System.Drawing.Size(104, 32);
this.button5.TabIndex = 17;
this.button5.Text = "删除邮件地址";
this.button5.Click += new System.EventHandler(this.button5_Click);
//
// label7
//
this.label7.Location = new System.Drawing.Point(208, 208);
this.label7.Name = "label7";
this.label7.Size = new System.Drawing.Size(80, 24);
this.label7.TabIndex = 18;
this.label7.Text = "邮件总数";
//
// label8
//
this.label8.Location = new System.Drawing.Point(208, 256);
this.label8.Name = "label8";
this.label8.Size = new System.Drawing.Size(80, 24);
this.label8.TabIndex = 19;
this.label8.Text = "完成数量";
//
// textBox6
//
this.textBox6.Location = new System.Drawing.Point(312, 208);
this.textBox6.Name = "textBox6";
this.textBox6.Size = new System.Drawing.Size(64, 21);
this.textBox6.TabIndex = 20;
this.textBox6.Text = "0";
//
// textBox7
//
this.textBox7.Location = new System.Drawing.Point(312, 256);
this.textBox7.Name = "textBox7";
this.textBox7.Size = new System.Drawing.Size(64, 21);
this.textBox7.TabIndex = 21;
this.textBox7.Text = "0";
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(640, 557);
this.Controls.Add(this.textBox7);
this.Controls.Add(this.textBox6);
this.Controls.Add(this.label8);
this.Controls.Add(this.label7);
this.Controls.Add(this.button5);
this.Controls.Add(this.textBox5);
this.Controls.Add(this.button4);
this.Controls.Add(this.label6);
this.Controls.Add(this.button3);
this.Controls.Add(this.textBox4);
this.Controls.Add(this.label5);
this.Controls.Add(this.textBox3);
this.Controls.Add(this.textBox2);
this.Controls.Add(this.label4);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.listBox2);
this.Controls.Add(this.listBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "系统批量发送HTML邮件";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void Form1_Load(object sender, System.EventArgs e)
{
this.Menu=mainMenu1;
textBox1.Text=System.Environment.CurrentDirectory+"//Email.txt";
}
private void menuItem3_Click(object sender, System.EventArgs e)
{
}
private void menuItem4_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void button1_Click(object sender, System.EventArgs e)
{
string txtFilePath=textBox1.Text;
string strline="";
StreamReader srReadLine = new StreamReader(
(System.IO.Stream)File.OpenRead(txtFilePath),
System.Text.Encoding.ASCII);
srReadLine.BaseStream.Seek(0, SeekOrigin.Begin);
while (srReadLine.Peek() > -1)
{
strline=srReadLine.ReadLine();
listBox1.Items.Add(strline);
}
srReadLine.Close();
textBox6.Text=listBox1.Items.Count.ToString();
}
private void button2_Click(object sender, System.EventArgs e)
{
for(int i=0;i<listBox1.Items.Count;i++)
{
String MailToAddress1=(string)listBox1.Items[i];
if (MailToAddress1 != "")
{
SendEmail(MailToAddress1);
}
}
textBox7.Text=listBox2.Items.Count.ToString();
}
public void SendEmail(string MailToAddress)
{
string MailFromAddress="csharp222@126.com";
string MailTitle=textBox2.Text;
string MailContent=textBox3.Text;
string MailServer="smtp.126.com";
string MailUserName="csharp222";
string MailPassword="123456";
MailMessage mailobject = new MailMessage();
mailobject.To = MailToAddress;
mailobject.From = MailFromAddress;
mailobject.Subject =MailTitle;
mailobject.Body =MailContent;
mailobject.BodyFormat=MailFormat.Html;
mailobject.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //basic authentication
mailobject.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", MailUserName); //set your username here
mailobject.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", MailPassword); //set your password here
SmtpMail.SmtpServer = MailServer;
SmtpMail.Send(mailobject);
listBox2.Items.Add(MailToAddress);
}
private void button3_Click(object sender, System.EventArgs e)
{
string strHtmlPagePath=textBox4.Text;
int at = 0;
int start = 0;
int notei=0;
int endi=0;
int[] myIntArray = new int[5];
while((start < strHtmlPagePath.Length) && (at > -1))
{
at = strHtmlPagePath.IndexOf('/', start);
if (at == -1) break;
myIntArray[notei]=at;
start = at+1;
notei = notei+1;
endi=at;
}
textBox2.Text=strHtmlPagePath.Substring(0,endi);
string strEmailContent=GetWeather(strHtmlPagePath);
string strEmailContentFileName=Application.StartupPath+"//EmailContent.txt";
StreamWriter strwriterobj=File.CreateText(strEmailContentFileName);
strwriterobj.Write(strEmailContent);
strwriterobj.Close();
textBox3.Text =strEmailContent;
}
private void button4_Click(object sender, System.EventArgs e)
{
textBox5.Text=GetLength(textBox3.Text).ToString();
}
int GetLength (string strTest)
{
ASCIIEncoding ascii = new ASCIIEncoding();
byte [] byteArr = ascii.GetBytes(strTest); /*利用ASCII对字符串编码并转化为一个
二进制数组*/
int i, length=0;
for (i = 0; i < strTest.Length; i++)
{
length++;
}
return length;
}
public string GetWeather(string url)
{
string weacherhtml=String.Empty;
HttpWebRequest rt=null;
HttpWebResponse rs=null;
Stream stream=null;
StreamReader sr=null;
rt=(HttpWebRequest)WebRequest.Create(url);
rs=(HttpWebResponse)rt.GetResponse();
stream=rs.GetResponseStream();
sr=new StreamReader(stream,System.Text.Encoding.Default);
weacherhtml=sr.ReadToEnd();
sr.Close();
stream.Close();
rs.Close();
return weacherhtml;
}
private void button5_Click(object sender, System.EventArgs e)
{
listBox1.Items.Remove(listBox1.SelectedItem);
}
}
}
相关推荐
C#发送邮件小程序源码 仅供大家一起学习参考!
C# 控制台批量发送邮件 说明:下载代码后将邮箱地址和密码修改成自己的即可运行,注释出标记了debug。
C#邮件自动发送程序、完整VS2008项目源代码,SMTP实现,可批量发送、抄送,可加附件,定时发送,代码有详细的注视,方便新手学习哈哈。
1:发邮件功能如下: a:批量添加邮箱 b:添加多个附件、并支持查看附件信息和移除附件。 2:因为免费,所以126,136服务器人家对咱 有控制:(我测试了126,136邮件) 1:邮箱虽已分组发送,但一次只能发送35个...
实例229 C#中实现文件拖放 317 实例230 文件比较 318 实例231 获取文件夹中的图标资源 319 实例232 获取文件夹下的所有文件夹及文件的名称 321 第7章 操作系统与Windows相关程序 324 7.1 启动相关 325 实例...
实例229 C#中实现文件拖放 317 实例230 文件比较 318 实例231 获取文件夹中的图标资源 319 实例232 获取文件夹下的所有文件夹及文件的名称 321 第7章 操作系统与Windows相关程序 324 7.1 启动相关 325 实例...
C#示例源码 C#示例 C#源码 C#示例源代码 C#源代码 注:一共五部分,请全部下载完成后,放同一目录下解决即可。 目录: 第1章 窗体及菜单设计 实例001 自定义最大化、最小化和关闭按钮 2 实例002 磁性窗体的...
实例229 C#中实现文件拖放 317 实例230 文件比较 318 实例231 获取文件夹中的图标资源 319 实例232 获取文件夹下的所有文件夹及文件的名称 321 第7章 操作系统与Windows相关程序 324 7.1 启动相关 325 实例...
8.2.5 邮件发送类的使用 188 8.2.6 使用正则表达式验证邮件格式 190 8.3 设计过程 191 8.3.1 数据库设计 191 8.3.2 系统登录 191 8.3.3 邮件发送实现 192 8.3.4 为邮件上传多个附件 193 8.3.5 邮件...
【功能】:批量修改指定目录下的所有文件和文件夹的时间属性创建时间属性的修改、最后修改时间属性...本程序是作者初学C#的第一个程序,可能有些地方处理的不够好,如有需要改善的地方,请发送邮件至 1834783759@qq.com
实例192 电子邮件的发送与接收 实例193 获取网络中所有工作组名称 实例194 列出指定工作组中的所有计算机名 实例195 监测当前网络连接状态 实例196 使用udp协议设计聊天室 第18章 注册表技术 实例197 禁止运行...
C#开发的winform小程序。可以实现邮件的批量发送的小工具。欢迎使用。
C#示例源码 C#示例 C#源码 C#示例源代码 C#源代码 C#源代码例子 C#例子 注意:本源代码共有20章节,分五部分上传,名称分别为:明日科技《C#示例源代码》(1-4)、明日科技《C#示例源代码》(1-4)、明日科技《C#...
8.2.5 邮件发送类的使用 8.2.6 使用正则表达式验证邮件格式 8.3 设计过程 8.3.1 数据库设计 8.3.2 系统登录 8.3.3 邮件发送实现 8.3.4 为邮件上传多个附件 8.3.5 邮件接收实现 8.3.6 查看邮件详细信息 8.3.7 下载...
C#示例源码 C#示例 C#源码 C#示例源代码 C#源代码 C#源代码例子 C#例子 注意:本源代码共有20章节,分五部分上传,名称分别为:明日科技《C#示例源代码》(1-4)、明日科技《C#示例源代码》(1-4)、明日科技《C#...
C#示例源码 C#示例 C#源码 C#示例源代码 C#源代码 注:一共五部分,请全部下载完成后,放同一目录下解决即可。 目录: 第1章 窗体及菜单设计 实例001 自定义最大化、最小化和关闭按钮 2 实例002 磁性窗体的...
8.2.5 邮件发送类的使用 8.2.6 使用正则表达式验证邮件格式 8.3 设计过程 8.3.1 数据库设计 8.3.2 系统登录 8.3.3 邮件发送实现 8.3.4 为邮件上传多个附件 8.3.5 邮件接收实现 8.3.6 查看邮件详细信息 8.3.7 下载...
此程序用C#语言开发,实现了Smtp,exchange两种发邮件方式,支持自定义自图片的签名,和群发附件, 提供源代码和程序文件,可以直接运行,属于绿色软件! 开发此程序主要是为了公司HR批量发工资条。提高了工作效率! ...