日期:2014-05-18 浏览次数:21147 次
SmtpClient smtp = new SmtpClient(); //实例化一个SmtpClient //可以支持SSL, smtp.EnableSsl = useSsl;//smtp服务器是否启用SSL加密//可以支持SSL, //可以支持 回复邮箱 ReplyTo MailMessage mm = new MailMessage(); //实例化一个邮件类 mm.ReplyTo = new MailAddress(replyToEmail, displayName,Encoding.Default);
//准备发送 SendCmd("MAIL FROM: <" + mail.MailFrom + ">\r\n");//必须加个‘<’、‘>’,否则出现500 bad Syntax 错误,即命令语法错误 orderText += "MAIL FROM: <" + mail.MailFrom + ">\r\n"; //if (GetStatusCode(ref orderText) != 250) //{ return false; } foreach (string to in mail.MailTo) { SendCmd("RCPT TO: <" + to + ">\r\n");//必须加个‘<’、‘>’,否则出现500 bad Syntax 错误,即命令语法错误 orderText += "RCPT TO: <" + to + ">\r\n"; //if (GetStatusCode(ref orderText) != 250) //{ return false; } } SendCmd("data\r\n"); orderText += "data\r\n"; //if (GetStatusCode(ref orderText) != 354) //{ return false; } StringBuilder content = new StringBuilder(); //邮件头 content.AppendFormat("From:{0}\r\n", mail.MailFrom); string toTxt = string.Empty; foreach (string to in mail.MailTo) { toTxt += to + ";"; } toTxt = toTxt.Substring(0, toTxt.Length - 1); content.AppendFormat("To:{0}\r\n", toTxt);//发送到达邮件 content.AppendFormat("Date:{0}\r\n", mail.SendDate.ToString());//发送时间 content.AppendFormat("Subject:{0}\r\n", mail.Subject);//邮件主题 //邮件格式 //邮件内容 content.Append("\r\n"); content.Append(mail.Body);//邮件内容 content.Append("\r\n.\r\n"); //邮件附件 SendCmd(content.ToString()); orderText += content.ToString();