1

I made a camera app that takes a pic and once a picture is taken i tap on a uibutton to compose a mail with that image as attachment. everything seems to be working fine even the image file in attachment can be seen while composing the email. when tap on 'send', and open my email id I do not receive any new inbox. here is the code

func sendEmail() {
    let composeVC = MFMailComposeViewController()
    composeVC.mailComposeDelegate = self
    // Configure the fields of the interface.
    composeVC.setToRecipients([email])
    composeVC.setSubject("Hello!")
    composeVC.setMessageBody("Hello this is my message body!", isHTML: false)
    let imageData: NSData = UIImagePNGRepresentation(pickedImage.image!)! as NSData
    composeVC.addAttachmentData(imageData as Data, mimeType: "image/jpeg", fileName: name)
    // Present the view controller modally.
    self.present(composeVC, animated: true, completion: nil)
}

func mailComposeController(_ controller: MFMailComposeViewController,
                           didFinishWith result: MFMailComposeResult, error: Error?) {
    controller.dismiss(animated: true, completion: nil)
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
N4SK
  • 700
  • 8
  • 25

1 Answers1

1

I found the issue & it was because I didn't allow the mail app on my iOS device access to "Mobile Data". So, don't forget to allow that access as your device will be sending mail via the apple id you logged in with.

N4SK
  • 700
  • 8
  • 25