最近用OpenSMTP给sohu免费信箱发邮件,发现中文名称的附件在sohu信箱收到是附件名称会是乱码,检查了一下源码,发现问题应该是出在OpenSmtp.Mail.Smtp的私有方法WriteToStream,修改后的代码如下:
把源代码导到SharpDevelop重新编译了一下就好使了,我用SharpDevelop作的OpenSMTP工程:
http://www.upload4asp.net/download.aspx?filename=T3BlblNtdHAucmFy
private void WriteToStream(ref NetworkStream nw, string line)
{
try
{
// byte[] arrToSend = Encoding.ASCII.GetBytes(line);
byte[] arrToSend = Encoding.Default.GetBytes(line); //modified by bestcomy
nw.Write(arrToSend, 0, arrToSend.Length);
//Console.WriteLine("[client]:" + line);
LogMessage(line, "[client]: ");
}
catch(System.Exception)
{
throw new SmtpException("Write to Stream threw an System.Exception");
}
}
{
try
{
// byte[] arrToSend = Encoding.ASCII.GetBytes(line);
byte[] arrToSend = Encoding.Default.GetBytes(line); //modified by bestcomy
nw.Write(arrToSend, 0, arrToSend.Length);
//Console.WriteLine("[client]:" + line);
LogMessage(line, "[client]: ");
}
catch(System.Exception)
{
throw new SmtpException("Write to Stream threw an System.Exception");
}
}
把源代码导到SharpDevelop重新编译了一下就好使了,我用SharpDevelop作的OpenSMTP工程:
http://www.upload4asp.net/download.aspx?filename=T3BlblNtdHAucmFy