Search code examples
lotus-notesmimelotuslotusscript

How to create a MIME mail with an attachment containing extended characters (with accents) using LotusScript


In a LotusScript agent I create a multi-part mail in MIME, using the MIME classes. It works, mails are sent correctly.

There's just one big problem: files with accented characters in their name aren't correctly transferred. The contents are correct, but the name isn't. I've tried in 100 ways, but either it isn't possible or I'm doing something completely wrong.

Here's (part of) my code:

Set Me.mc = Me.mr.createChildEntity()
Set Me.mh = Me.mc.CreateHeader("Content-Disposition")
Call Me.mh.SetHeaderVal(disposition + {; filename="} & attName & {";charset="iso-8859-1"} )
Set Me.mh = Me.mc.CreateHeader("Content-ID")
Call Me.mh.SetHeaderVal( |<| & attName & |>| )
Set stream = Me.session.CreateStream
If stream.Open(attFile) Then
    Call Me.mc.SetContentFromBytes(stream, strContentType & {; charset="iso-8859-1"; name="} & attName & {"}, ENC_IDENTITY_BINARY)
    Call stream.Close
End If

If I create a mail manually in Notes and send the same file it works, but the file's name is coded. How to pull this one off??

Update: I added the following function to encode attName:

Function URLEncode(s As String, cset As String) As String
    Dim v As Variant

    v= Evaluate(|@ReplaceSubstring(@URLEncode("| + cset + |";"| + s + |"); "%"; "=")|)
    URLEncode= "=?" + cset + "?Q?" + v(0) + "?="
End Function  

Solution

  • I could not find any method to encode the parameters. Looks like you have to encode the parameter yourself.

    @URLEncode( encodingFormat ; token )
    

    Should encode the string and then yo can add the =?ISO-8859-1?Q? and ?= to the string.

    Or you can use encodeText from the javax.mail.internet package end wrap that in LS2J