'skpsmtpmessage: how to to attach a pdf file to a mail

I try to attach a pdf file and send a mail with it and a text to explain the content of the pdf using skpsmtpmessage. I've an error : NSInvalidArgumentException', reason: '-[__NSCFString appendString:]: nil argument' I probably have an error I don’t see. The file exist and I've the message "File available" Can you help me Thank you very much Georges

{{{

do {
              let documentDirectory = try FileManager.default.url(for:        .documentDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
              let fileUrl = documentDirectory.appendingPathComponent("EngagementsFestivalU13").appendingPathExtension("pdf")
              if FileManager.default.fileExists(atPath: fileUrl.path) {
              print("FILE AVAILABLE")
              let fileAttachment = "attachment;" + fileUrl.path
            
              let fileMessagePart2 :[String : String] = [
                kSKPSMTPPartContentTypeKey:"text/directory;\r\n\tx-unix-mode=0644;\r\n\tname=\"EngagementsFestivalU13.pdf\"" ,kSKPSMTPPartContentDispositionKey:fileAttachment]

              let fileMessagePart1 :[String : String] = [kSKPSMTPPartContentTypeKey: "text/plain; charset=UTF-8", kSKPSMTPPartMessageKey: htmlBody]
              message.parts = [fileMessagePart1, fileMessagePart2]
              message.delegate = self
              
              message.send()
                }
            else {
               var style = ToastStyle()
               style.messageColor = .blue
               style.backgroundColor = .yellow
               self.view.makeToast("Le fichier n'a pas été trouvé, veuillez l'envoyer par mail à 'adresse : [email protected], MERCI!!", duration: 3.0, position: .bottom, style: style)
                        }
                    }
            catch {
               print(error)
                    }
}}}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source