测试之家淘宝店:主营软件测试定制服务
http://shop71136398.taobao.com/
软件评测试考试论坛:http://www.testdao.com/forum-113-1.html
2012软件评测师考试群:28388329
批量发送邮件工具
上一篇 /
下一篇 2010-09-04 14:37:45
/ 个人分类:自动化测试
最近一直在
测试邮件系统,需要批量发送邮件,自己编写了一个批量发送邮件工具,具体参考了网上的代码,不过还是有待改善,因为感觉性能上比较慢,一些异常未处理,不过还是拿出来共享下,记录我C#学习进度。
using System;51Testing软件测试网
~(i*aL7yO$A
using System.Collections;
$JFi;I5TR k0using System.Drawing;51Testing软件测试网V.W
_Y,d:L
using System.Windows.Forms;51Testing软件测试网gi4M*J{"L!Y*M
using System.Net;51Testing软件测试网e4jy:{n5NQ0g
using System.Net.Mail;
,dT"LLi6ry0~0using System.Text;51Testing软件测试网4v9w{"pX)e
using System.IO;
namespace FromMailSend
51Testing软件测试网+M4G`)},_{
I?cgg AI0 /// <summary>
51Testing软件测试网X3d,M(|}d /// Description of MainForm.
51Testing软件测试网%m4i~}v] rC+D /// </summary>
r/p |Sw5R&T0 public partial class MainForm. Form
51Testing软件测试网:x2\)edw'P {
CB0u0_K0E/w0 public MainForm()
!iU+t!G*p!K,\a'r\B0 {
51Testing软件测试网%M#^V+|I //
gD'Ah(p`!t0 // The InitializeComponent() call is required for
Windows Forms designer support.
51Testing软件测试网.D}7gZHq u //
51Testing软件测试网@&\t7uF}$t InitializeComponent();
?2M0N#Ago]#n:{~ep \0 51Testing软件测试网&W)az%Z BLbi2L} //
51Testing软件测试网.[Z6]4\n6y:rVB // TODO: Add constructor code after the InitializeComponent() call.
51Testing软件测试网b$[8_U+j6z
M(U
Y'gE //
51Testing软件测试网 kh(ZH"j4Ne }
51Testing软件测试网a P
}2J'}E { void Button1Click(object sender, EventArgs e)
51Testing软件测试网@B.zNJ'v {
51Testing软件测试网 NTG|Ws9G!g //mail message
BO"YZNcU:V0 MailAddress from = new MailAddress("
test@gmail.com");
51Testing软件测试网Y$F7B4m^'N;QC MailMessage myMail = new MailMessage();
51Testing软件测试网)Jm^[*uau%@ myMail.To.Add(new MailAddress(ToTxt.Text));
%F{@@(V|-ys$i0 myMail.From = from;
51Testing软件测试网m{;I6\,m O
s myMail.Subject = SubjectTxt.Text;
/S e%wz?*N0 myMail.SubjectEncoding = Encoding.UTF8;
51Testing软件测试网BV~'y,tI myMail.Body = BodyTxt.Text;
OJ4dE0o#}.[0 myMail.BodyEncoding = Encoding.UTF8;
51Testing软件测试网%hR;]#Gv:V| myMail.IsBodyHtml = false;
51Testing软件测试网2]#?F C:W myMail.Priority = MailPriority.High;
J p@W~b0 'g1LLF#Le0 //Attachment
string attahmentName=this.tbAttachment.Text.Trim().ToString();
2SM6p\C V0 if (!string.Equals(attahmentName, null) && !string.Equals(attahmentName, ""))
1e|9[#n9i-BW1W1z0 {51Testing软件测试网3M\K5|;X!e:HO
CDs
Attachment data = new Attachment(attahmentName, System.Net.Mime.MediaTypeNames.Application.Octet);
*zX;w2ul1xZ_u0 myMail.Attachments.Add(data);
W!sB"@ ogh0 }
Z l#Ao
gA_` w$f0 else51Testing软件测试网]dv;zZZ y'pM
{51Testing软件测试网9k x:B f"M
wq o6m/w
tbAttachment.Text = null;51Testing软件测试网ya&A