/// <summary> /// 用指定的编码发 /// </summary> /// <param name="encoding">编码</param> public void SendToEMail() { System.Net.Mail.MailMessage MM = new System.Net.Mail.MailMessage(FromEmail, ToEmail, Subject, Content); MM.Priority = System.Net.Mail.MailPriority.High; MM.IsBodyHtml = IsHtml; MM.BodyEncoding = Encoding; String sendUser; int s = FromEmail.IndexOf('<'); int e = FromEmail.IndexOf('>'); if (s > 0 && e > 0) { FromEmail = FromEmail.Substring(s + 1, e - s - 1); } String[] EmailParts = FromEmail.Split("@".ToCharArray(), 2); sendUser = EmailParts[0]; SmtpClient SC = new SmtpClient(SmtpServer, ServerPort); SC.DeliveryMethod = SmtpDeliveryMethod.Network; SC.Timeout = 100000; SC.Credentials = new System.Net.NetworkCredential(sendUser, FromEmailPwd); SC.Send(MM); }
public void SendToEmailOld() { System.Web.Mail.MailMessage message = new System.Web.Mail.MailMessage(); message.Subject = Subject; message.BodyFormat = IsHtml ? MailFormat.Html : MailFormat.Text; // 设置邮件正文为html 格式 message.BodyEncoding = Encoding; message.Body = Content; // 设置邮件内容 message.From = FromEmail; message.To = ToEmail; String sendUser; int s = FromEmail.IndexOf('<'); int e = FromEmail.IndexOf('>'); if (s > 0 && e > 0) { FromEmail = FromEmail.Substring(s + 1, e - s - 1); } String[] EmailParts = FromEmail.Split("@".ToCharArray(), 2); sendUser = EmailParts[0]; message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate", "1"); //设置服务器需要身份验证 message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendusername", sendUser); //设置用户名 message.Fields.Add("http://schemas.microsoft.com/cdo/configuration/sendpassword", FromEmailPwd); //设置密码 SmtpMail.SmtpServer = SmtpServer; SmtpMail.Send(message); //发送邮件。 }