|
throw new Exception ("登陆阶段失败");
if (userName != "") { // 需要身份验证 if (!Command (tcp.GetStream(), "AUTH LOGIN", "334")) throw new Exception ("身份验证阶段失败"); string nameB64 = ToBase64 (userName); // 此处将username转换为Base64码 if (!Command (tcp.GetStream(), nameB64, "334")) throw new Exception ("身份验证阶段失败"); string passB64 = ToBase64 (password); // 此处将password转换为Base64码 if (!Command (tcp.GetStream(), passB64, "235")) throw new Exception ("身份验证阶段失败"); }
// 准备发送 WriteString (tcp.GetStream(), "mail From: " + from); WriteString (tcp.GetStream(), "rcpt to: " + to); WriteString (tcp.GetStream(), "data");
// 发送邮件头 WriteString (tcp.GetStream(), "Date: " + DateTime.Now); // 时间 WriteString (tcp.GetStream(), "From: " + fromName + "<" + from + ">"); // 发件人 WriteString (tcp.GetStream(), "Subject: " + subject); // 主题 WriteString (tcp.GetStream(), "To:" + toName + "<" + to + ">"); // 收件人
//邮件格式 WriteString (tcp.GetStream(), "Content-Type: multipart/mixed; boundary=\"unique-boundary-1\""); WriteString (tcp.GetStream(), "Reply-To:" + from); // 回复地址 WriteString (tcp.GetStream(), "X-Priority:" + priority); // 优先级 WriteString (tcp.GetStream(), "MIME-Version:1.0"); // MIME版本
// 数据ID,随意 // WriteString (tcp.GetStream(), "Message-Id: " + DateTime.Now.ToFileTime() + "@security.com"); WriteString (tcp.GetStream(), "Content-Transfer-Encoding:" + encoding); // 内容编码 WriteString (tcp.GetStream(), "X-Mailer:JcPersonal.Utility.MailSender"); // 邮件发送者 WriteString (tcp.GetStream(), "");
WriteString (tcp.GetStream(), ToBase64 ("This is a multi-part message in MIME format.")); WriteString (tcp.GetStream(), "");
// 从此处开始进行分隔输入 WriteString (tcp.GetStream(), "--unique-boundary-1");
// 在此处定义第二个分隔符 WriteString (tcp.GetStream(), "Content-Type: multipart/alternative;Boundary=\"unique-boundary-2\""); WriteString (tcp.GetStream(), "");
if(!isHtml)
上一篇:使用ASP.NET开发邮件发送系统
下一篇:基于.NET的邮件解决方案
|