Swift MFMailComposeViewController addAttachmentData JPG set max resolution
<p>First of all, I'm new with Swift so sorry if I did something wrong.</p>

<p>I try to send an email with multiple images as attachment(s). But I can add all the images but they are at the full resolution. </p>

<p>Is it possible to limit the resolution of the images that are stored in an UIImage array? (now the email with 2 images will be 20MB instead 488KB)</p>

<p>Here some code:</p>

<pre><code>    func configuredMailComposeViewController(image: [UIImage]) -&gt; MFMailComposeViewController {
        let mailComposerVC = MFMailComposeViewController()
        mailComposerVC.mailComposeDelegate = self

        var counter = 1;
        for img in image {
            let imageData: NSData = UIImagePNGRepresentation(img)!
            mailComposerVC.addAttachmentData(imageData, mimeType: "image/jpeg", fileName: "image\(counter).jpg")
            counter += 1
        }

        mailComposerVC.setToRecipients(["email"])
        mailComposerVC.setSubject("subject")
        mailComposerVC.setMessageBody("message", isHTML: true)

        return mailComposerVC
    }
</code></pre>

<p>And the images will be created here:</p>

<pre><code>@IBAction func takePhoto(sender: UIButton) {
        imagePicker = UIImagePickerController()
        imagePicker.delegate = self
        imagePicker.sourceType = .Camera

        presentViewController(imagePicker, animated: true, completion: nil)
}

func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    imagePicker.dismissViewControllerAnimated(true, completion: nil)

    var image_taken: UIImage!
    image_taken = info[UIImagePickerControllerOriginalImage] as? UIImage

    var image: UIImage!
    image = image_taken

    imageArray.append(image)

}


var imagePicker: UIImagePickerController!
</code></pre>

<p>And now call the createEmail method:</p>

<pre><code>//send data to email
@IBAction func sendDataToServer(sender: UIBarButtonItem) {
    composeMail(imageArray)
}
</code></pre>