问题
I'm sending a pdf through MFMailComposeViewController. The sender's signature is seen as an attachment when viewed in Outlook, but not the iOS native mail app.Everything else works as expected.
What is the reason the signature is showing an attachment?
@IBAction func sendSpecSheetWithEmailButton(_ sender: subclassedUIButton) {
buttonURL = sender.urlString!
specName = sender.specSheetName!
let fileURL = URL(string: buttonURL)
if fileURL == URL(string: "https://www.example.com") {
alertUserSpecNotAvailable(fileURL: fileURL!, specName: specName)
} else {
sendMail(fileURL: fileURL!, attachmentType: "pdf", to: [""], cc: ["team@example.com"], subject: "Spec Sheet", message: "The spec sheet you requested is attached. \n\nSent via Our iPhone app")
}
}
Someone asked a similar question on here years ago, but there was never a clear answer.
Edit: here is sendMail()
func sendMail (fileURL: URL, attachmentType: String, to: [String]?, cc: [String], subject: String, message: String) {
if MFMailComposeViewController.canSendMail() {
let mail = MFMailComposeViewController()
mail.mailComposeDelegate = self
mail.setSubject(subject)
mail.setToRecipients(to)
mail.setCcRecipients(cc)
mail.setMessageBody(message, isHTML: false)
switch attachmentType {
case "pdf":
if let fileData = NSData(contentsOf: fileURL as URL) {
print("File data loaded.")
mail.addAttachmentData( fileData as Data, mimeType: "application/pdf", fileName: specName)
}
return self.present(mail, animated: true, completion: nil)
case "url":
mail.setMessageBody("The requested spec sheet is can be found here: \(fileURL)", isHTML: true)
return self.present(mail, animated: true, completion: nil)
case "none":
return self.present(mail, animated: true, completion: nil)
default: break
}
} else {
self.showSendMailErrorAlert()
}
}
回答1:
After some more digging, this is an issue with the exchange server and not with Swift/ iOS/ etc. It has to do with the way that Exchange expects email content to be ordered. I haven't found a clear answer on if the newer versions of Exchange address the issue. The MIT link specifically mentions Exchange Server 2007 & 2010. Also, I was able to confirm that the issue is when the mail is being sent by Exchange, not received.
http://kb.mit.edu/confluence/pages/viewpage.action?pageId=4981187
https://support.microsoft.com/en-us/help/969854/the-body-of-a-message-is-shown-incorrectly-as-an-attachment-if-you-try
来源:https://stackoverflow.com/questions/47043596/mfmailcomposeviewcontroller-attaches-signature-as-txt-file