wpf操作邮箱极为方便,下面我贴段代码,想必大家更愿意直接上代码吧
1 /// <summary> 2 /// 发送邮件 3 /// </summary> 4 /// <param name="toAddr">收件人人地址</param> 5 /// <param name="Cc">抄送地址</param> 6 /// <param name="Mcc">密送地址</param> 7 /// <param name="from">发送人地址</param> 8 /// <param name="content">邮件内容</param> 9 /// <param name="subject">邮件标题</param> 10 /// <param name="attach">附件内容</param> 11 /// <param name="Pwd">发送人邮件密码</param> 12 public void SendMailByPlainFormat(string toAddr, string Cc, string Mcc, string from, string content, string subject, string attach, string Pwd) 13 { 14 MailMessage mailobj = new MailMessage(); 15 mailobj.From = new MailAddress(from);//发件人 16 mailobj.To.Add(toAddr); //收件人 17 if (Cc != "") 18 mailobj.CC.Add(Cc); //抄送 19 if (Mcc != "") 20 mailobj.Bcc.Add(Mcc); //密送 21 mailobj.Priority = MailPriority.High; //发送优先级 22 mailobj.Subject = subject; //主题 23 mailobj.Body = content; //内容 24 mailobj.IsBodyHtml = true; //内容是否可以为html形式 25 mailobj.BodyEncoding = Encoding.Default; 26 if (attach != "") 27 { 28 char[] delim = new char[] { ';' }; 29 foreach (string substr in attach.Split(delim)) 30 { 31 Attachment MyAttach = new Attachment(substr); 32 //MailAttachment MyAttach = new MailAttachment(substr); 33 mailobj.Attachments.Add(MyAttach); 34 35 } 36 } 37 38 SmtpClient smtp = new SmtpClient(); 39 smtp.Host = this.server; //服务器 40 smtp.Port = this.port; //端口 41 smtp.Credentials = new System.Net.NetworkCredential(this.user, this.password); //用户名和密码 45 smtp.Send(mailobj); 46 }
好,因为我的附件添加时,是用";"隔开的,所以上面也做了这样的处理