日期:2014-05-17  浏览次数:20584 次

Net.Mail发送邮件,附件变成了乱码(dat文件)
代码:

string strSmtpServer = smtpServer;
            string strFrom = mailFrom;
            string strMailProxyUser = mailProxyUser;
            string strMailProxyPass = mailProxyPassword;
            SmtpClient client = new SmtpClient(strSmtpServer);
            client.UseDefaultCredentials = false;
            client.Credentials = new System.Net.NetworkCredential(strMailProxyUser, strMailProxyPass);
            client.DeliveryMethod = SmtpDeliveryMethod.Network;
            client.Port = 25;
            client.Timeout = 3000000;
            MailAddress from = new MailAddress(strFrom);
            MailAddress to = new MailAddress(strTo, strToDisplayName);
            System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(from, to);
            message.Subject = strSubject;
            message.Body = strBody;
            System.Net.Mail.Attachment attachment = null;
            message.SubjectEncoding = Encoding.UTF8;
            message.HeadersEncoding = Encoding.UTF8;
            message.BodyEncoding = Encoding.UTF8;
            message.IsBodyHtml = true;
            if (attachmentFiles != null)
            {
                foreach (string files in attachmentFiles)
                {
                    if (System.IO.File.Exists(files))
                    {
                        attachment = new System.Net.Mail.Attachment(files);
                        attachment.NameEncoding = Encoding.UTF8;                    &