How to add a image in email body using MFMailComposeViewController

前端 未结 4 1676
故里飘歌
故里飘歌 2020-12-01 05:31

I am trying to find out the best way to add an image inside the body of the email and not as attachment in ios.

1) Apple has provided a function \"addAttach

4条回答
  •  悲哀的现实
    2020-12-01 06:22

    Set email format as HTML. This code is woking fine in my app.

    MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
    
    NSString *htmlMsg = @"

    This is your message

    "; NSData *jpegData = UIImageJPEGRepresentation(emailImage, 1.0); NSString *fileName = @"test"; fileName = [fileName stringByAppendingPathExtension:@"jpeg"]; [emailDialog addAttachmentData:jpegData mimeType:@"image/jpeg" fileName:fileName]; emailDialog setSubject:@"email subject"]; [emailDialog setMessageBody:htmlMsg isHTML:YES]; [self presentModalViewController:emailDialog animated:YES]; [emailDialog release];

    Swift 5

    import MessageUI
    
        func composeMail() {
    
            let mailComposeVC = MFMailComposeViewController()
    
            mailComposeVC.addAttachmentData(UIImage(named: "emailImage")!.jpegData(compressionQuality: CGFloat(1.0))!, mimeType: "image/jpeg", fileName:  "test.jpeg")
    
            mailComposeVC.setSubject("Email Subject")
    
            mailComposeVC.setMessageBody("

    This is your message

    ", isHTML: true) self.present(mailComposeVC, animated: true, completion: nil) }

提交回复
热议问题