Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a attachment in outlook programatically swift 3

I have opened the outlook app and send a file in it. I am able to open the outlook and set the To,Subject and Body but not sure how to attach file in the document directory The file is at path

  var paths = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)
    let documentsDirectory = paths[0]
    let fileName = "supportdata.log"
    let logFilePath = (documentsDirectory as NSString).appendingPathComponent(fileName)

let scheme : String = "ms-outlook://[email protected]&subject=Support data &body=Please find the attached file" 
     if let url = URL(string: scheme) {
        UIApplication.shared.open(url, options: [:], completionHandler: {
            (success) in
            if (success)
            {
                print("Open \(scheme): \(success)")
            }                     
        })
    }
like image 530
Warrior Avatar asked Sep 13 '17 18:09

Warrior


People also ask

How do I insert an attachment into an Outlook email?

Attach a file to a message Create a message, or for an existing message, click Reply, Reply All, or Forward. In the message window, on the Message tab, in the Include group, click Attach File. Browse to and click the file that you want to attach, and then click Insert.

How do I attach a file in Outlook IOS?

Attach a file In a new email or a reply, tap the paperclip icon and then Attach file. Tap See All and select a file. Choose a file and then tap Insert OneDrive for Business Link.

How do I use attachments in Outlook 365?

You can open an attachment from the Reading Pane or from an open message. In either case, double-click the attachment to open it. To open an attachment from the message list, right-click the message that has the attachment, click View Attachments, and then click the name of the attachment.


1 Answers

Sadly, it is not possible. There are two main issues:

  1. You are deeplinking to an app, meaning sending an on-device message to another app that is effectively the same as a normal URI with a GET method parameterized string. String only, no major data/files can be sent. The URL Scheme below is for reference. And it is the same as what you're using; though I think you are missing an '=' in your ms-outlook:// string.

    ms-outlook://compose?to=%@&subject=%@&body=%@

  2. iOS is pretty strict with app sandboxes, you cannot pass local files to other apps unless they are on the same app/file domain (e.g. you're the owner of both apps). There are a few alternatives that work in a watered-down format, but are not relevant for this scenario. Here's the thing, even if you could, Microsoft would need to support this file attachment feature, which it doesn't. Sadly, there's nothing we can do about it on our side... other than asking Microsoft to add the feature.

However, if you want to do this in the apple mail app, that's certainly doable.

like image 156
Chris J Avatar answered Oct 31 '22 10:10

Chris J