我从网上找了一篇能够支持ESmtp的源码,回来以后看到不支持CC和BCC就自己在
人家的基础上进行了添加,可是问题出现了,邮件的源文件应该没有问题,邮件构造成功,发件人那里多个人也能正常接收.发送的时候没有任何问题.
为了方便大家看清问题,我将构造好的邮件源码,和Send()函数列出,请大家都来帮忙呀!
这是构造好的邮件信息:
Return-Path: <angiin@sina.com>
Delivered-To: angiin@sina.com.cn
Received: (qmail 79165 invoked from network); 17 Sep 2003 01:41:29 -0000
Received: from unknown (HELO smtp.sina.com.cn) (61.55.3.65)
by 202.106.187.156 with SMTP; 17 Sep 2003 01:41:29 -0000
From:angiin@163.com<angiin@163.com>
To:angiin@sina.com.cn<angiin@sina.com.cn>
Cc:changlibin@msn.com<changlibin@msn.com>
Bcc:faster@163.net<faster@163.net>
Subject:=?GB2312?B?v7S/tM3izfjKx7K7ysfE3Lm7t6LLzQ==?=
X-Priority:Normal
X-MSMail-Priority:Normal
Importance:Normal
X-Mailer: Huolx.Pubclass
MIME-Version: 1.0
Content-Type: text/plain;
boundary="----=_NextPart_000_00D6_01C29593.AAB31770"
------=_NextPart_000_00D6_01C29593.AAB31770
charset="gb2312"
Content-Transfer-Encoding: base64
这是Send()过程
private bool SendEmail()
{
//连接网络
try
{
tc=new TcpClient(mailserver,mailserverport);
}
catch(Exception e)
{
errmsg=e.ToString();
return false;
}
ns = tc.GetStream();
SMTPCodeAdd();
//验证网络连接是否正确
if(RightCodeHT[RecvResponse().Substring(0,3)]==null)
{
errmsg="网络连接失败";
return false;
}
string[] SendBuffer;
string SendBufferstr;
//进行SMTP验证
if(ESmtp)
{
SendBuffer=new String[4];
SendBuffer[0]="EHLO " + mailserver + enter;
SendBuffer[1]="AUTH LOGIN" + enter;
SendBuffer[2]=Base64Encode(username) + enter;
SendBuffer[3]=Base64Encode(password) + enter;
if(!Dialog(SendBuffer,"SMTP服务器验证失败,请核对用户名和密码。"))
return false;
}
else
{
SendBufferstr="HELO " + mailserver + enter;
if(!Dialog(SendBufferstr,""))
return false;
}
//
SendBufferstr="MAIL FROM:<" + From + ">" + enter;
if(!Dialog(SendBufferstr,"发件人地址错误,或不能为空"))
return false;
//
SendBuffer=new string[recipientmaxnum];
for(int i=0;i<recipientmaxnum;i++)
{
SendBuffer[i]="RCPT TO:<" + Recipient[i].ToString() +">" + enter;
}
if(!Dialog(SendBuffer,"收件人地址有误"))
return false;
SendBufferstr="DATA" + enter;
if(!Dialog(SendBufferstr,""))
return false;
SendBufferstr="From:" + FromName + "<" + From +">" +enter;
///SendBufferstr += "To:=?"+Charset.ToUpper()+"?B?"+Base64Encode(RecipientName)+"?="+"<"+Recipient[0]+">"+enter;
SendBufferstr+="To:";
for(int i=0;i<recipientmaxnum;i++)
{
if (i<recipientmaxnum-1)
{
SendBufferstr+=Recipient[i].ToString() + "<" + Recipient[i].ToString() +">,";
}
else
{
SendBufferstr+=Recipient[i].ToString() + "<" + Recipient[i].ToString() +">";
}
}
SendBufferstr+=enter;
SendBufferstr+="Cc:";
for(int i=0;i<recipientCCmaxnum;i++)
{
if (i<recipientCCmaxnum-1)
{
SendBufferstr+=RecipientCC[i].ToString() + "<" + RecipientCC[i].ToString() +">,";
}
else
SendBufferstr+=RecipientCC[i].ToString() + "<" + RecipientCC[i].ToString() +">";
}
SendBufferstr+=enter;
SendBufferstr+="Bcc:";
for(int i=0;i<recipientBCCmaxnum;i++)
{
if (i<recipientBCCmaxnum-1)
SendBufferstr+=RecipientBCC[i].ToString() + "<" + RecipientBCC[i].ToString() +">,";
else
SendBufferstr+=RecipientBCC[i].ToString() + "<" + RecipientBCC[i].ToString() +">";
}
SendBufferstr+=enter;
if((Charset=="")||(Charset==null))
{
SendBufferstr+="Subject:" + Subject + enter;
}
else
{
SendBufferstr+="Subject:" + "=?" + Charset.ToUpper() + "?B?" + Base64Encode(Subject) +"?=" +enter;
}
SendBufferstr+="X-Priority:" + priority + enter;
SendBufferstr+="X-MSMail-Priority:" + priority + enter;
SendBufferstr+="Importance:" + priority + enter;
SendBufferstr+="X-Mailer: Huolx.Pubclass" + enter;
SendBufferstr+="MIME-Version: 1.0" + enter;
if(Html)
{
SendBufferstr+="Content-Type: text/html;" + enter;
}
else
{
SendBufferstr+="Content-Type: text/plain;" + enter;
}
///SendBufferstr += "Content-Type: "+contenttype+";"+enter;//内容格式和分隔符
SendBufferstr += " boundary=\"----=_NextPart_000_00D6_01C29593.AAB31770\""+enter;
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770"+enter;
if(Charset=="")
{
SendBufferstr+=" charset=\"iso-8859-1\"" + enter;
}
else
{
SendBufferstr+=" charset=\"" + Charset.ToLower() + "\"" + enter;
}
//SendBufferstr += "Content-Transfer-Encoding: base64"+enter;
SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter;
SendBufferstr+= Base64Encode(Body) + enter;
if(Attachments.Count!=0)
{
foreach(string filepath in Attachments)
{
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770"+enter;
SendBufferstr += "Content-Type: application/octet-stream"+enter;
SendBufferstr += " name=\"=?"+Charset.ToUpper()+"?B?"+Base64Encode(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter;
SendBufferstr += "Content-Transfer-Encoding: base64"+enter;
SendBufferstr += "Content-Disposition: attachment;"+enter;
SendBufferstr += " filename=\"=?"+Charset.ToUpper()+"?B?"+Base64Encode(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter+enter;
SendBufferstr += GetStream(filepath)+enter+enter;
}
}
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770--"+enter+enter;
SendBufferstr += enter + "." + enter;
if(!Dialog(SendBufferstr,"错误信件信息"))
return false;
SendBufferstr="QUIT" + enter;
if(!Dialog(SendBufferstr,"断开连接时错误"))
return false;
ns.Close();
tc.Close();
return true;
}
Well, I aware few problem in your code as below.
1) MIME message is just simply a text, it will not affect mail sending at all, you can put whatever string inside. However, "Bcc" is not supose to be there. Otherwise, how to make it a "Blind CC"?
2) RCPT command should include all the recipients, this includes "To", "Cc" and "Bcc". You code only handles "To" but not "Cc" & "Bcc"
已经发了,谢谢