How to set Content-disposition in mail.headers

Hi,

i want to set the Content-disposition in the mail.header before sending my mail.

I tried it like this:

mail.Headers.AppendHeader("Content-Disposition", "attachment; filename=" + AttachmentName)

AttachmentName represents the filename of the attachment, e.g. filename.pdf.

But in the received Mailheader, the Content-disposition only show this:

Content-disposition: attachment

Is it posible in xojo to set the correct Content-disposition?

Michael

did you check EmailAttachment class?
It should do the content-disposition automatically.

But the mail-headers of the mail that are send by my app are showing only a content-disposition: attachment. So some mail-receivers get an attachment with the name attachment.pdf instead of the-real-filename.pdf.

How can i check the EmailAttachment Class?

Which informations do you use in your mail-headers when using this in xojo?

I use this:

Message-ID (build from a date- and time-string plus @ and the fqdn, important for not getting a bad Spam-Score)
Mime-Version (1.0)
Content-Type (text/plain, charset=utf-8)
Content-Transfer-Encoding (base64)

then i choose the attachment-file, load it and set attachment.MIMEType to application/pdf.

Works fine on OS X and Windows, but sometimes the receiver gets an Attachment with the Name ATTACHMENT.PDF instead of the real filename. Here is the code use for this:

  Dim d As New Date
  Dim messageDate As String
  Dim messageTime As String
  
  messageDate = ReplaceAll(d.ShortDate.ToText, ".", "")
  messageTime = ReplaceAll(d.LongTime.ToText, ":", "")
  
  Dim messageID As String
  
  messageID = "<" + messageDate + "." + messageTime + "@" + sendMailSocket.Address + ">"
  
  mail = new EmailMessage
  mail.Headers.AppendHeader("Message-ID", messageID)
  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 = txtSender.Text
  mail.AddRecipient(txtReceiver.Text)
  mail.AddBCCRecipient("mail@uniformis.de")
  mail.Subject = "=?utf-8?b?" + EncodeBase64(ConvertEncoding(txtSubject.Text, Encodings.UTF8)) + "?="
  mail.BodyPlainText = TextArea1.Text
  
  if mailHasAttachment = True then
    
    attachment = new EmailAttachment
    attachment.LoadFromFile(GetFolderItem(AttachmentPath, FolderItem.PathTypeNative))
    attachment.MIMEType = "application/pdf"
    attachment.Name = "=?utf-8?b?" + EncodeBase64(AttachmentName, 0) + "?="
    
    #if TargetMacOS
      attachment.MacCreator = "prvw"
      attachment.MacType = "PDF"
    #endif
    
    mail.Attachments.Append(attachment)

This is how it looks in other mails with attachment not coming from xojo.

right before the attachment:

Content-Type: application/pdf
Content-Disposition: attachment; filename="some-filename.pdf"
Content-Transfer-Encoding: base64

do you use MBS Plugin?
There we have CURLEMailMBS class which may help you.
There we set the file name in the attachment with content disposition.

No. I don’t have your Plugins.

You got 2 problems here:

  1. Some mail clients like Mail or Outlook change the mail they receive. So what you see may not be what you sent.
  2. Content-Disposition needs to be set for every attachment, because it can be different for every attachment.

Hello, again.

What i’ve learned from Email in the last days is that i have to choose the best compromise. There does not seems to be the perfect solution to handle all plattforms and different client.

How do i set content-disposition in xojo? For me it seems that things like attachment.MIMEType should handle this (which i set to application/pdf), but in the header the content-disposition says only attachment. No Application/PDF, no filename.

That what i would expect in “Content-disposition” is placed (within the header) in “Content-Type” just in front of the attachment:

Content-Type: application/pdf; name="=?utf-8?b?Z2VzY2hhzIhmdHN2ZXJsYXVmLWHMiG/MiHXMiEHMiE/MiFXMiMOfLnBkZg==?=";
 x-mac-type="504446"
 x-mac-creator="70727677"
Content-transfer-encoding: Base64
Content-disposition: attachment

Would you do something totally different then my code does when sending Mails with Attachment?

  Dim messageID As String
  
  messageID = "<" + messageDate + "." + messageTime + "@" + sendMailSocket.Address + ">"
  
  mail = new EmailMessage
  mail.Headers.AppendHeader("Message-ID", messageID)
  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 = txtSender.Text
  mail.AddRecipient(txtReceiver.Text)
  mail.AddBCCRecipient("mail@uniformis.de")
  mail.Subject = "=?utf-8?b?" + EncodeBase64(txtSubject.Text, 0) + "?="
  mail.BodyPlainText = TextArea1.Text
  
  if mailHasAttachment = True then
    
    attachment = new EmailAttachment
    attachment.LoadFromFile(GetFolderItem(AttachmentPath, FolderItem.PathTypeNative))
    attachment.Name = "=?utf-8?b?" + EncodeBase64(AttachmentName, 0) + "?="
    attachment.MIMEType = "application/pdf"
    
    #if TargetMacOS
      attachment.MacCreator = "prvw"
      attachment.MacType = "PDF"
    #endif
    
    mail.Attachments.Append(attachment)
    
  end if
  
  sendMailSocket.Messages.Append(mail)
  sendMailSocket.SendMail

Michael

[quote=170715:@Christian Schmitz]do you use MBS Plugin?
There we have CURLEMailMBS class which may help you.
There we set the file name in the attachment with content disposition.[/quote]

Don’t get me wrong, Christian. I just want my apps pure Xojo, no Plugins.