邮件附件和内容传输编码设置(黑莓手机的问题) [英] Mail Attachment and its Content Transfer Encoding setting (BlackBerry problem)

查看:262
本文介绍了邮件附件和内容传输编码设置(黑莓手机的问题)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用C#code在不同平台上发送一些电子邮件给不同的用户使用邮件客户端:黑莓,iPhone,PC,MAC等。以下是摘录:

I use a C# code to send some e-mails to different users with mail clients on different platforms: BlackBerry, iPhone, Pc, Mac, etc. Here is the snippet:

Attachment attachment = null;
        if (attachNameFile!=null) 
        {
            attachment = new Attachment(attachNameFile, new System.Net.Mime.ContentType(attachMimeType));
        }

        SmtpClient smtp = new SmtpClient
        {
            Host = this.smtpServer,
            Port = this.smtpPort,
            EnableSsl = false,
            DeliveryMethod = SmtpDeliveryMethod.Network,
            UseDefaultCredentials = false,
            Credentials = new NetworkCredential()
        };

        using (MailMessage message = new MailMessage())
        {
            message.From = fromAddress;
            if (macTo != null) message.To.AddRangeUnique(macTo);
            if (macCc!=null) message.CC.AddRangeUnique(macCc);
            if (macCcn != null) message.Bcc.AddRangeUnique(macCcn);
            message.Subject = subject;
            message.Body = sb.ToString();

            if (replyTo != null)
                message.ReplyTo = new MailAddress(replyTo);
            else
                message.ReplyTo = fromAddress;

            if (attachment!=null)  
            { 
                message.Attachments.Add(attachment);                
            }
            smtp.Send(message);
        }

一些用户告诉我,他或她收到的消息没有附件。附件是文本(UTF8)文件。
经过一番分析,我看到该附件在邮件正文显示,只有一些邮件客户端显示它作为附件。这是不是我的问题,但黑莓手机有一些问题,这种附件的,因为它表明只有身体和切断附件。但它在谷歌,易网邮,Thunderbird等等。

Some user told me that the message he or she receives doesn't have the attachment. The attachment is a text (UTF8) file. After some analysis, I saw that the attachment is shown in the body of the mail and only some mail clients show it as an attachment. It is not a problem for me, but BlackBerry has some problem with this kind of attachments, because it shows only the body and cut off the attachment. But it works in Google, iMail, Thunderbird, etc. etc.

我分析消息的来源,我看到了attacchment的 ContentTransferEncoding 是8位:

I analysed the source of the message and I saw the ContentTransferEncoding of the attacchment is 8 bit:

Content-Transfer-Encoding: 8bit
Content-Type: text/plain; name=Attachment.2324333.txt

我想我解决我的问题,如果我在C#中设置的 ContentTransferEncoding 的对象属性的附件的Base64 编码:

Attachment attachment = null;
        if (attachNameFile!=null) 
        {
            attachment = new Attachment(attachNameFile, new System.Net.Mime.ContentType(attachMimeType));
            attachment.TransferEncoding = System.Net.Mime.TransferEncoding.Base64;
        }

你是否认为这是一个很好的和工作方法?我是否需要设置其他属性?

Do you think it is a good and working approach? Do I have to set other properties?

感谢所有

推荐答案

请参阅:<一href=\"http://stackoverflow.com/questions/2825950/sending-email-with-attachments-from-c-attachments-arrive-as-part-1-2-in-thunder\">Sending从C#等附件的邮件,附件在到达雷鸟1.2部分

内容处理是我的问题的解决方案。

Content Disposition was the solution for my problem.

这篇关于邮件附件和内容传输编码设置(黑莓手机的问题)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆