private bool SendMailTest() { bool blnFlag = false; /* * mail发送方法:不需指定用户名和密码 */ /* * 方法一 * * 可写为: SmtpClient client = new SmtpClient(); client.Host = "host"; */ SmtpClient client = new SmtpClient("host", 25); client.UseDefaultCredentials = false; client.DeliveryMethod = SmtpDeliveryMethod.Network; /* * message也可以写为如下: * MailMessage message = new MailMessage(); message.From = new MailAddress("mailAddress", "name"); message.To.Add(new MailAddress("mailAddress", "name")); */ MailMessage message = new MailMessage(new MailAddress("mailAddress", "name"), new MailAddress("mailAddress", "name")); message.Subject = "TestSubject"; message.Body = "TestBody"; message.IsBodyHtml = true; message.Priority = MailPriority.High; try { client.Send(message); blnFlag = true; } catch (Exception ex) { throw ex; } return blnFlag; } private static bool SendMail() { bool strRe = false; //host为所使用发送邮箱的服务器 SmtpClient client = new SmtpClient("host", 25);//txtStmp.Text client.UseDefaultCredentials = false; client.DeliveryMethod = SmtpDeliveryMethod.Network; /*为发件人的邮箱名和密码; 如邮箱为123456@163.com 用户名为123456 密码当然你发件人邮箱的密码 */ client.Credentials = new NetworkCredential("userName", "password"); MailMessage SendMes = new MailMessage(new MailAddress("fromMailAddress"), new MailAddress("toMailAddress")); //邮件主题 SendMes.Subject = "textSubject"; //主题编码 SendMes.SubjectEncoding = Encoding.UTF8; //邮件正文 SendMes.Body = "textBody"; //正文编码 SendMes.BodyEncoding = Encoding.UTF8; //设置为HTML格式 SendMes.IsBodyHtml = true; //优先级 SendMes.Priority = MailPriority.High; try { client.Send(SendMes); strRe = true; } catch (Exception ex) { throw ex; } return strRe; } private bool SendMailTest1() { bool blnFlag = false; SmtpClient client = new SmtpClient(); client.Host = "host"; try { client.Send("guoli.wang@yidatec.com", "guoli.wang@yidatec.com", "1", "222"); blnFlag = true; } catch (Exception ex) { throw ex; } return blnFlag; } /* * 带附件的发送方法 */ //a.zip位置:E:/Test/WinFormTest/WinFormTest/bin/Debug Attachment attachment = new Attachment("a.zip", MediaTypeNames.Application.Zip); message.Attachments.Add(attachment);