邮件附件及其内容传输编码设置(BlackBerry问题) [英] Mail Attachment and its Content Transfer Encoding setting (BlackBerry problem)

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

问题描述

我使用C#代码在不同平台上的邮件客户端向不同的用户发送一些电子邮件:BlackBerry,iPhone,Pc,Mac等。这是代码片段:

 附件附件= 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()
};

使用(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)文件。
经过一番分析,我看到附件显示在邮件正文中,只有一些邮件客户端显示为附件。这对我来说不是问题,但是BlackBerry对这种附件有一些问题,因为它只显示身体并切断了附件。但是它可以在Google,iMail,Thunderbird等中使用。



我分析了消息的来源,我看到了 ContentTransferEncoding 8位元素$ 8

$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ name = Attachment.2324333.txt

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

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

你认为这是一个很好的工作方法吗?我必须设置其他属性?



感谢所有

解决方案

请参阅:发送电子邮件附带C#附件,附件作为Thunderbird的第1.2部分到达



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


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);
        }

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.

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

I think I resolve my problem if I set the ContentTransferEncoding property of the object Attachment in C# to Base64 encoding:

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?

Thanks to all

解决方案

See: Sending email with attachments from C#, attachments arrive as Part 1.2 in Thunderbird

Content Disposition was the solution for my problem.

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

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