文件名称:
tingMailSendSystem--仿OutLook的邮件编辑面板
开发工具:
文件大小: 555kb
下载次数: 0
上传时间: 2011-09-30
详细说明: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net; using System.Net.Mail; using System.IO; namespace CNPOPSOFT.Controls.Demo { public partial class MailSender : Form { private string filenameok = ""; private string filenameno = ""; private MailMessage message; public MailSender() { InitializeComponent(); } private void buttonSend_Click(object sender, EventArgs e) { string[] ls = System.IO.File.ReadAllLines (this.textBoxTo.Text.Trim(), System.Text.Encoding.Default); if (ls.Length > 0) { string folder = Application.StartupPath + "\\Logs"; if (!Directory.Exists(folder)) Directory.CreateDirectory(folder); filenameok = folder + "\\" + DateTime.Now.ToString ("yyyy_MM_dd HH mm ss") + "_ok.txt"; filenameno = folder + "\\" + DateTime.Now.ToString ("yyyy_MM_dd HH mm ss") + "_no.txt"; for (int a = 0; a < ls.Length; a++) { bool s = false; if (ls[a].ToString().Length < 1 && ls[a].ToString ().IndexOf("@") == -1) continue; else s = Sendemail(ls[a].ToString()); if (s) { FileStream fs1 = new FileStream(filenameok, FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs1); sw.WriteLine("\r\n"); sw.WriteLine ("*******************************"); sw.WriteLine(ls[a].ToString()); sw.WriteLine(DateTime.Now.ToString()); sw.WriteLine ("*******************************"); sw.Close(); fs1.Close(); } else { FileStream fs2 = new FileStream(filenameno, FileMode.Append, FileAccess.Write); StreamWriter sw = new StreamWriter(fs2); sw.WriteLine("\r\n"); sw.WriteLine("******************************"); sw.WriteLine(ls[a].ToString()); sw.WriteLine(DateTime.Now.ToString()); sw.WriteLine("******************************"); sw.Close(); fs2.Close(); } } } if (File.Exists(filenameok)) this.textBox3.Text = filenameok; else this.textBox3.Text = "全部没有发送成功!"; if (File.Exists(filenameno)) this.textBox4.Text = filenameno; else this.textBox4.Text = "全部发送成功!"; } public bool Sendemail(string toemail) { bool flag = false; MailMessage message = BuildMessage(toemail); string host = "smtp." + message.From.Host; int port = 25; string userid = this.textBox1.Text; string password = this.textBox2.Text; SmtpClient smtp = new SmtpClient(host, port); smtp.Credentials = new NetworkCredential(userid, password); smtp.DeliveryMethod = SmtpDeliveryMethod.Network; try { smtp.Send(message); flag = true; //MessageBox.Show("发送成功!", "示例", MessageBoxButtons.OK, MessageBoxIcon.Information); } catch (Exception ex) { flag = false; //MessageBox.Show("发送失败!\r\n" + ex.Message, "示 例", MessageBoxButtons.OK, MessageBoxIcon.Warning); } return flag; } private MailMessage BuildMessage(string toemail) { string from = this.textBox1.Text; //string to = textBoxTo.Text; string subproject = textBoxSubject.Text; string[] images =null; string body =""; if (this.textBox5.Text.Length < 1) { images = htmlEditor1.Images; body = htmlEditor1.Text; } else { body = System.IO.File.ReadAllText (this.textBox5.Text.ToString(), Encoding.Default); } message = new MailMessage(); message.From = new MailAddress(from); message.To.Add(new MailAddress(toemail)); message.Subject = subproject; message.IsBodyHtml = true; if (images != null) { for (int i = 0, count = images.Length; i < count; ++i) { string image = images[i]; if (image.Trim() == "") { continue; } if (!image.StartsWith("file")) { continue; } string path = Path.GetFullPath(image.Replace("%20", " ").Replace("file:///", "")); string cid = string.Format("image_{0:00}", i); Attachment attach = new Attachment(path); attach.Name = Path.GetFileName(path); attach.ContentId = cid; message.Attachments.Add(attach); body = body.Replace(path, string.Format("cid:{0}", cid));//5+1+a+s+p+x } } message.Body = body; return message; } private void btnadd_Click(object sender, EventArgs e) { if (this.openFileDialog1.ShowDialog() == DialogResult.OK) this.textBoxTo.Text = this.openFileDialog1.FileName; } private void button1_Click(object sender, EventArgs e) { if (this.textBox3.Text.Length > 25) System.Diagnostics.Process.Start(filenameok); } private void button2_Click(object sender, EventArgs e) { if (this.textBox4.Text.Length > 25) System.Diagnostics.Process.Start(filenameno); } private void button3_Click(object sender, EventArgs e) { if (this.openFileDialog2.ShowDialog() == DialogResult.OK) this.textBox5.Text = this.openFileDialog2.FileName; } } } ...展开收缩
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.