最近开发中用了lion兄弟写的smtp邮件发送类,根据自己的需要适当做了点修改
邮件Subject和Body还有附件都以Base64编码
但接收到的邮件都是编码后的内容,一堆的垃圾字符,没有还原
求教高手指点迷津,感激不尽
付上一段代码(太长,放不完)
if(m_Charset=="")
{
SendBufferstr+="Subject:" + m_Subject + enter;
}
else
{
SendBufferstr+="Subject:" + "=?" + m_Charset.ToUpper() + "?B?" + Base64Encode(m_Subject) +"?=" +enter;
} SendBufferstr+="X-Priority:" + m_Priority + enter;
SendBufferstr+="X-MSMail-Priority:" + m_Priority + enter;
SendBufferstr+="Importance:" + m_Priority + enter;
SendBufferstr+="X-Mailer: Huolx.Pubclass" + enter;
SendBufferstr+="MIME-Version: 1.0" + enter; SendBufferstr += "Content-Type: multipart/mixed;"+enter;//内容格式和分隔符
SendBufferstr += " boundary=\"----=_NextPart_000_00D6_01C29593.AAB31770\""+enter;
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770"+enter; if(m_BodyFormat == MailFormat.Html)
{
SendBufferstr+="Content-Type: text/html;" + enter;
}
else
{
SendBufferstr+="Content-Type: text/plain;" + enter;
} if(m_Charset=="")
{
SendBufferstr+=" charset=\"iso-8859-1\"" + enter;
}
else
{
SendBufferstr+=" charset=\"" + m_Charset.ToLower() + "\"" + enter;
} SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter; SendBufferstr+= Base64Encode(m_Body) + enter;
//SendBufferstr+= "=?" + m_Charset.ToUpper() + "?B?" + Base64Encode(m_Body) +"?=" + enter;
if(m_Attachments.Count!=0)
{
foreach(string filepath in m_Attachments)
{
if( File.Exists(filepath ) )
{
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770"+enter;
SendBufferstr += "Content-Type: application/octet-stream"+enter;
SendBufferstr += " name=\"=?"+m_Charset.ToUpper()+"?B?"+Base64Encode(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter;
SendBufferstr += "Content-Transfer-Encoding: base64"+enter;
SendBufferstr += "Content-Disposition: attachment;"+enter;
SendBufferstr += " filename=\"=?"+m_Charset.ToUpper()+"?B?"+Base64Encode(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter+enter;
SendBufferstr += GetByes(filepath)+enter+enter;
}
}
}
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770--"+enter+enter; SendBufferstr += enter + "." + enter;
邮件Subject和Body还有附件都以Base64编码
但接收到的邮件都是编码后的内容,一堆的垃圾字符,没有还原
求教高手指点迷津,感激不尽
付上一段代码(太长,放不完)
if(m_Charset=="")
{
SendBufferstr+="Subject:" + m_Subject + enter;
}
else
{
SendBufferstr+="Subject:" + "=?" + m_Charset.ToUpper() + "?B?" + Base64Encode(m_Subject) +"?=" +enter;
} SendBufferstr+="X-Priority:" + m_Priority + enter;
SendBufferstr+="X-MSMail-Priority:" + m_Priority + enter;
SendBufferstr+="Importance:" + m_Priority + enter;
SendBufferstr+="X-Mailer: Huolx.Pubclass" + enter;
SendBufferstr+="MIME-Version: 1.0" + enter; SendBufferstr += "Content-Type: multipart/mixed;"+enter;//内容格式和分隔符
SendBufferstr += " boundary=\"----=_NextPart_000_00D6_01C29593.AAB31770\""+enter;
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770"+enter; if(m_BodyFormat == MailFormat.Html)
{
SendBufferstr+="Content-Type: text/html;" + enter;
}
else
{
SendBufferstr+="Content-Type: text/plain;" + enter;
} if(m_Charset=="")
{
SendBufferstr+=" charset=\"iso-8859-1\"" + enter;
}
else
{
SendBufferstr+=" charset=\"" + m_Charset.ToLower() + "\"" + enter;
} SendBufferstr+="Content-Transfer-Encoding: base64" + enter + enter; SendBufferstr+= Base64Encode(m_Body) + enter;
//SendBufferstr+= "=?" + m_Charset.ToUpper() + "?B?" + Base64Encode(m_Body) +"?=" + enter;
if(m_Attachments.Count!=0)
{
foreach(string filepath in m_Attachments)
{
if( File.Exists(filepath ) )
{
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770"+enter;
SendBufferstr += "Content-Type: application/octet-stream"+enter;
SendBufferstr += " name=\"=?"+m_Charset.ToUpper()+"?B?"+Base64Encode(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter;
SendBufferstr += "Content-Transfer-Encoding: base64"+enter;
SendBufferstr += "Content-Disposition: attachment;"+enter;
SendBufferstr += " filename=\"=?"+m_Charset.ToUpper()+"?B?"+Base64Encode(filepath.Substring(filepath.LastIndexOf("\\")+1))+"?=\""+enter+enter;
SendBufferstr += GetByes(filepath)+enter+enter;
}
}
}
SendBufferstr += "------=_NextPart_000_00D6_01C29593.AAB31770--"+enter+enter; SendBufferstr += enter + "." + enter;
解决方案 »
- 急!!!!!如何让未绑定数据的DataGrid显示用来编辑的空白行?
- 注册表查询出来的SubKey数据和实际有差别
- sendkeys中的按键问题
- System.DateTime.Now.Ticks.ToString();
- 怎样获取局域网内所有的机器的打印机
- c#连接数据库的问题..
- TreeView及ListBox问题!!!
- 精通C#请进来,高分求救 急!!!!
- 急急!c/s下面操作treeview运行后怎么老是selectednode怎么老是为空?
- ListViewItem无参构造函数总是创建一个空的column列吗?
- c#中用System.Drawing和System.Windows.Forms的问题
- 2个窗体传送信息
{
if((source==null)||(source.Length ==0))
throw new ArgumentException("source is not valid"); ToBase64Transform tb64 = new ToBase64Transform();
MemoryStream stm = new MemoryStream();
int pos = 0;
byte[] buff; while (pos + 3 < source.Length)
{
buff = tb64.TransformFinalBlock (source, pos, 3);
stm.Write (buff, 0, buff.Length);
pos += 3;
} buff = tb64.TransformFinalBlock (source, pos, source.Length - pos);
stm.Write (buff, 0, buff.Length); return stm.ToArray();
}