代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
CSharp
】
批量发送邮件程序中用到的两个函数
作者:
xqf222
/ 发布于
2014/2/25
/
379
/// <summary> /// 发送单封邮件 /// </summary> /// <param name="MailToAddress"></param> public void SendOneEmail(string MailToAddress) { string MailFromAddress=txtEmail.Text; string MailTitle=txtEmailTitle.Text; string MailContent=txtEmailContent.Text; string MailSmtpServer=textBoxsmtp.Text; int TempMailServer=MailFromAddress.IndexOf("@",0); string MailUserName=MailFromAddress.Substring(0,TempMailServer); string MailPassword=txtPassword.Text; //string MailDdomain=MailFromAddress.Substring((TempMailServer+1),(MailFromAddress.Length-TempMailServer-1)); try { //实例化MailMessage对象 System.Web.Mail.MailMessage mail=new System.Web.Mail.MailMessage(); //定义邮件的发送地址 mail.From=MailFromAddress; //定义邮件的接收地址 //设置以分号分隔的收件人电子邮件地址列表 mail.To=MailToAddress; //定义邮件的主题 mail.Subject=MailTitle; //设置电子邮件正文的内容类型 //在这里我们以HTML的格式发送 mail.BodyFormat=System.Web.Mail.MailFormat.Html; //设置电子邮件的正文 mail.Body=MailContent; //SMTP服务器 //许多SMTP服务器都需要身份验证 System.Web.Mail.SmtpMail.SmtpServer=MailSmtpServer; //验证 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //登陆名 mail.Fields.Add("<A href="http://schemas.microsoft.com/cdo/configuration/sendusername",MailUserName">http://schemas.microsoft.com/cdo/configuration/sendusername",MailUserName); //登陆密码 mail.Fields.Add("<A href="http://schemas.microsoft.com/cdo/configuration/sendpassword",MailPassword">http://schemas.microsoft.com/cdo/configuration/sendpassword",MailPassword); //发送 System.Web.Mail.SmtpMail.Send(mail); listBox2.Items.Add(MailToAddress); txtSCount.Text=listBox2.Items.Count.ToString(); string strEmailSuccessFileName=Application.StartupPath+"//EmailSuccess.txt"; if (File.Exists(strEmailSuccessFileName)) { StreamWriter strwriterobj=File.AppendText(strEmailSuccessFileName); strwriterobj.WriteLine(MailToAddress); strwriterobj.Close(); } else { StreamWriter strwriterobj=File.CreateText(strEmailSuccessFileName); strwriterobj.WriteLine(MailToAddress); strwriterobj.Close(); } } catch(Exception ee) { listBox3.Items.Add(MailToAddress); txtFCount.Text=listBox3.Items.Count.ToString(); txtFReport.Text=MailToAddress + "邮件发送失败" +ee.ToString(); string strEmailFailed=MailToAddress; string strEmailFailedFileName=Application.StartupPath+"//EmailFailed.txt"; if (File.Exists(strEmailFailedFileName)) { StreamWriter strwriterobj=File.AppendText(strEmailFailedFileName); strwriterobj.WriteLine(strEmailFailed); strwriterobj.Close(); } else { StreamWriter strwriterobj=File.CreateText(strEmailFailedFileName); strwriterobj.WriteLine(strEmailFailed); strwriterobj.Close(); } } txtFinish.Text=(int.Parse(txtFinish.Text)+1).ToString(); } /// <summary> /// 密送邮件 /// </summary> /// <param name="MailToAddress"></param> /// <param name="MailBccAddress"></param> private void SendTwoEmail(string MailToAddress,string MailBccAddress) { string MailFromAddress=txtEmail.Text; string MailTitle=txtEmailTitle.Text; string MailContent=txtEmailContent.Text; string MailSmtpServer=textBoxsmtp.Text; int TempMailServer=MailFromAddress.IndexOf("@",0); string MailUserName=MailFromAddress.Substring(0,TempMailServer).Trim(); string MailPassword=txtPassword.Text.Trim(); //string MailDdomain=MailFromAddress.Substring((TempMailServer+1),(MailFromAddress.Length-TempMailServer-1)); try { //实例化MailMessage对象 System.Web.Mail.MailMessage mail=new System.Web.Mail.MailMessage(); //定义邮件的发送地址 mail.From=MailFromAddress; //定义邮件的接收地址 //设置以分号分隔的收件人电子邮件地址列表 mail.To=MailToAddress; //定义邮件的主题 mail.Subject=MailTitle; //设置电子邮件正文的内容类型 //在这里我们以HTML的格式发送 mail.BodyFormat=System.Web.Mail.MailFormat.Html; //设置电子邮件的正文 mail.Body=MailContent; //mail.BodyEncoding.EncodingName. //定义邮件的暗送地址 //设置以分号分隔的电子邮件地址列表 mail.Bcc=MailBccAddress; //定义邮件的抄送地址 .抄送会显示在收件人列表中 //设置以分号分隔的电子邮件地址列表 //mail.Cc="xqf222@hotmail.com"; //SMTP服务器 //许多SMTP服务器都需要身份验证 System.Web.Mail.SmtpMail.SmtpServer=MailSmtpServer; //验证 mail.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //登陆名 mail.Fields.Add("<A href="http://schemas.microsoft.com/cdo/configuration/sendusername",MailUserName">http://schemas.microsoft.com/cdo/configuration/sendusername",MailUserName); //登陆密码 mail.Fields.Add("<A href="http://schemas.microsoft.com/cdo/configuration/sendpassword",MailPassword">http://schemas.microsoft.com/cdo/configuration/sendpassword",MailPassword); //发送 System.Web.Mail.SmtpMail.Send(mail); listBox2.Items.Add(MailToAddress); listBox2.Items.Add(MailBccAddress); txtSCount.Text=listBox2.Items.Count.ToString(); string strEmailSuccessFileName=Application.StartupPath+"//EmailSuccess.txt"; if (File.Exists(strEmailSuccessFileName)) { StreamWriter strwriterobj=File.AppendText(strEmailSuccessFileName); strwriterobj.WriteLine(MailToAddress); strwriterobj.WriteLine(MailBccAddress); strwriterobj.Close(); } else { StreamWriter strwriterobj=File.CreateText(strEmailSuccessFileName); strwriterobj.WriteLine(MailToAddress); strwriterobj.WriteLine(MailBccAddress); strwriterobj.Close(); } } catch(Exception ee) { listBox3.Items.Add(MailToAddress); listBox3.Items.Add(MailBccAddress); txtFCount.Text=listBox3.Items.Count.ToString(); txtFReport.Text= "邮件发送失败地址:" +"/r/n"+ MailToAddress+"/r/n" +MailBccAddress+ "/r/n" +ee.ToString(); string strEmailFailedFileName=Application.StartupPath+"//EmailFailed.txt"; if (File.Exists(strEmailFailedFileName)) { StreamWriter strwriterobj=File.AppendText(strEmailFailedFileName); strwriterobj.WriteLine(MailToAddress); strwriterobj.WriteLine(MailBccAddress); strwriterobj.Close(); } else { StreamWriter strwriterobj=File.CreateText(strEmailFailedFileName); strwriterobj.WriteLine(MailToAddress); strwriterobj.WriteLine(MailBccAddress); strwriterobj.Close(); } } txtFinish.Text=(int.Parse(txtFinish.Text)+1).ToString(); }
试试其它关键字
批量发送邮件
同语言下
.
文件IO 操作类库
.
Check图片类型[JPEG(.jpg 、.jpeg),TIF,GIF,BMP,PNG,P
.
机器名和IP取得(IPV4 IPV6)
.
Tiff转换Bitmap
.
linqHelper
.
MadieHelper.cs
.
RegHelper.cs
.
如果关闭一个窗体后激活另一个窗体的事件或方法
.
创建日志通用类
.
串口辅助开发类
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
xqf222
贡献的其它代码
(
82
)
.
VB编写的登录局域网内的sql2000数据库服务器
.
ASP .NET登录界面用户验证码
.
VB操作ACCESS数据库
.
批量发送邮件程序
.
批量抓取网页代码中的HTTP和邮件地址
.
禁止站外提交参数测试
.
FTP网站文件到本地的
.
调用对应的应用程打开文件
.
抓取邮件内容解析
.
保存文件时候的弹出选择要保存的文件夹带新建文件夹效
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3