c# 邮件发送功能
//统一由一个邮箱发送录用通知 string strfrom = "";//发件人邮箱地址 string strpow = "";//邮箱密码 string strserver = "";//发送邮件服务器 string strto = "";//收件人地址 string strtitle = "邮件标题"; string strdody = "<div style='font-size:14px;'>邮件内容</div>"; string file1 = Server.MapPath("附件.doc");//附件地址1 string file2 = Server.MapPath("附件.pdf");//附件地址2 //发送邮件方法 //Send(strserver, strfrom, strpow, strto, strtitle, strdody); SmtpClient client = new SmtpClient(strserver); // client.UseDefaultCredentials = false; client.UseDefaultCredentials = true; client.Credentials = new System.Net.NetworkCredential(strfrom, strpow); client.DeliveryMethod = SmtpDeliveryMethod.Network; Byte[] b = Encoding.Default.GetBytes(strdody); strdody = Encoding.GetEncoding("gb2312").GetString(b).ToString(); //建立邮件附件类的一个对象,语法格式为System.Net.Mail.Attachment(文件名,文件格式) System.Net.Mail.Attachment myAttachment1 = new System.Net.Mail.Attachment( file1, System.Net.Mime.MediaTypeNames.Application.Octet); System.Net.Mail.Attachment myAttachment2 = new System.Net.Mail.Attachment( file2, System.Net.Mime.MediaTypeNames.Application.Octet); MailMessage message = new MailMessage(strfrom, strto, strtitle, strdody); message.Attachments.Add(myAttachment1);//用smtpclient对象里attachments属性,添加上面设置好的myattachment message.Attachments.Add(myAttachment2); message.BodyEncoding = Encoding.UTF8; message.IsBodyHtml = true; client.Send(message);
发送邮件中有很多默认的方法,若以后遇到问题随时更新!