Mime Attachment Problem

Hi All,

I have created a class to send a mail with two attached images (.jpg). The proccess works fine, but when the user receive the information, he can see the images in PC and laptop without problems, but not in tablets and mobiles.

In tables and mobiles, the images are being shown with the name: “mime-attachment” but is not possible show the image. I’m not sure if my code for header is correct, I’ll appreciate any suggestion to clarify the code or improve it. I can not find what I doing bad.


  'Customizing mail parameters
  Mail = New EmailMessage
  Mail.fromAddress=sFromAddress
  Mail.subject= sSubject
  Mail.bodyPlainText = sTextMessage
  [b]Mail.headers.SetHeader "Content-Type","image/jpeg"
  Mail.headers.appendHeader "MIME-Version","1.0"
  Mail.headers.appendHeader "X-Mailer","Email"[/b]
  Mail.addRecipient(sToAddress)

  'Customizing attachment files
  If sAttachFileA<>"" Then
    File = New EmailAttachment
    File.loadFromFile GetFolderItem(sAttachFileA)
    Mail.attachments.append File
  End If
  
  If sAttachFileB<>"" Then
    File = New EmailAttachment
    File.loadFromFile GetFolderItem(sAttachFileB)
    Mail.attachments.append File
  End If
  
  'Send mail
  Self.Messages.Append mail
  Self.SendMail

Thanks in advance.

The only problem I see in your code is this here:

Mail.headers.SetHeader "Content-Type","image/jpeg"

This doesn’t make sense. You could try with a non-plain message body. Recently there was a discussion about attachment names messed up. They have a duplicate names like “filename.txtfilename.txt”: <https://xojo.com/issue/42655> . Directly manipulating the source doesn’t work. Therefore some users switched to using CURLMBS.

Hi Beatrix,

Thanks for your replay. I forgot mention in my previous mail that the problem of visualization is presented in tables and mobiles just for iPad and iPhone, in others devices, the attached images can be visualized properly.

I think that Apple has some restriction for headers with .jpg images, but I’m not sure what would be the correct code in the header to show properly these images with iPad/iPhone.

I have changed the code, but problem persist.
[i]`

Mail.headers.appendHeader “X-Mailer”,“Email”
Mail.Headers.AppendHeader(“Mime-Version”, “1.0”)
Mail.Headers.AppendHeader(“Content-Type”, “text/plain; charset=utf-8”)
Mail.Headers.AppendHeader(“Content-Transfer-Encoding”, “base64”)

Mail.fromAddress=sFromAddress
Mail.subject= sSubject
Mail.bodyPlainText = sTextMessage
Mail.addRecipient(sToAddress)

'Customizing attachment files
If sAttachFileA<>"" Then
File = New EmailAttachment
File.MIMEType=“image/jpeg”
File.MIMEType=“image/jpg”

File.loadFromFile GetFolderItem(sAttachFileA)
Mail.attachments.append File
End If

If sAttachFileB<>"" Then
File = New EmailAttachment
File.MIMEType=“image/jpeg”
File.MIMEType=“image/jpg”

File.loadFromFile GetFolderItem(sAttachFileB)
Mail.attachments.append File
End If[/i]

`

I’ll check your thread, perhaps I can find some solution.

You can only set the mime type once per attachment. Also, while you are specifying base64 in the headers, you’re not inserting base64 data. Try leaving off all of the headers except your x-mailer header and see if that works.