Mail Attachment and its content encoding settings (BlackBerry problem)

I use C # code to send some email messages to different users with email clients on different platforms: BlackBerry, iPhone, Pc, Mac, etc. Here is a 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 does not have an application. An attachment is a text file (UTF8). After some analysis, I saw that the attachment is shown in the body of the letter, and only some email clients show it as an attachment. This is not a problem for me, but BlackBerry has some problems with such attachments, because it only shows the body and disables the attachment. But it works on Google, iMail, Thunderbird, etc. Etc.

I analyzed the source of the message, and I saw that ContentTransferEncoding for attacchment has 8 bits:

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

I think that I will solve my problem if I set the ContentTransferEncoding property of the C # attachment in 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 this is a good and effective approach? Should I set other properties?

Thank you all

0
source share
3 answers
+2
source

Looking at some attachments coming from my BlackBerry, I think you need to add a Content-Disposition header:

 Content-Transfer-Encoding: base64 Content-Type: text/plain Content-Disposition: attachment; filename="myfilename.bin" 
+3
source

It seems that you are doing everything right, other email clients prove it. Try BASE64, there is a good chance BlackBerry will like it, but you cannot be sure until you see it :).

0
source

Source: https://habr.com/ru/post/897900/


All Articles