wpf操作邮箱极为方便,下面我贴段代码,想必大家更愿意直接上代码吧
1 ///2 /// 发送邮件 3 /// 4 /// 收件人人地址 5 /// 抄送地址 6 /// 密送地址 7 /// 发送人地址 8 /// 邮件内容 9 /// 邮件标题10 /// 附件内容11 /// 发送人邮件密码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 }