Sending out HTML email with IMG tag from an iPhone App using MFMailComposeViewController class

后端 未结 4 1146
北恋
北恋 2020-12-30 18:23

I am using MFMailComposeViewController class to send out formatted HTML email from my iPhone app. I need to include an image in the email and I added am IMG tag to my emailb

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-30 18:33

    Here is the code which was working for me,

    Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));

            if (mailClass != nil)
            {
    
                // We must always check whether the current device is configured for sending emails
    
    
                UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    
                UIGraphicsEndImageContext();
                MFMailComposeViewController *composeVC = [[MFMailComposeViewController alloc] init];
                composeVC.mailComposeDelegate = self;
                [composeVC setSubject:@"test"];
                NSString *messageBody = @"";
                [composeVC setMessageBody:messageBody isHTML:NO];
                UIImage *artworkImage = viewImage;
                NSData *artworkJPEGRepresentation = nil;
                if (artworkImage)
                {
                    artworkJPEGRepresentation = UIImageJPEGRepresentation(artworkImage, 0.7);
                }
                if (artworkJPEGRepresentation) 
                {
                    [composeVC addAttachmentData:artworkJPEGRepresentation mimeType:@"image/jpeg" fileName:@"Quote.jpg"];
                }
    
                NSString *emailBody = @"Find out more  App at Test";//add code
                const char *urtfstring = [emailBody UTF8String];
                NSData *HtmlData = [NSData dataWithBytes:urtfstring length:strlen(urtfstring)];
                [composeVC addAttachmentData:HtmlData mimeType:@"text/html" fileName:@""];
                //Add code
                [self presentModalViewController:composeVC animated:YES];
                [composeVC release];
                [self dismissModalViewControllerAnimated:YES];
                UIGraphicsEndImageContext();
    

提交回复
热议问题