1

我使用MFMailComposeViewController以发送电子邮件,如何设置电子邮件正文中的某些文本之后的第一个图像?

有了这个代码,我能够得到的图像,但图像来后的文本细节, 我wan't第一图像和文字后,

这里是我的代码,

MFMailComposeViewController *mail = [[MFMailComposeViewController alloc] init]; 
    mail.mailComposeDelegate = self; 

    if ([MFMailComposeViewController canSendMail]) { 
     //Setting up the Subject, recipients, and message body. 
     [mail setToRecipients:[NSArray arrayWithObjects:Emailid,nil]]; 
     [mail setSubject:@"Receipt"]; 

     NSData *photoData = UIImageJPEGRepresentation([UIImage imageNamed:@"Gift.png"], 1); 
     [mail addAttachmentData:photoData mimeType:@"image/jpg" fileName:[NSString stringWithFormat:@"photo.png"]]; 

     [mail setMessageBody:@"Receipt" isHTML:NO]; 
     NSString *emailBody; 




     emailBody = [NSString stringWithFormat:@ 
        "<br>Purchase Amount:   </br> "  "$ %@" 
        "<br>Amount Received:  </br> "  "$ %@" 
        "<br>Change: </br> "  "$ %@" 
        ,AmountData,txtAmount.text,ChangeAmount.text]; 


     [mail setMessageBody:emailBody isHTML:YES]; 

请任何机构建议我我该怎么做?

回答

5

因为我这方面的知识是不是只加入图片作为附件,你可以做如下,以显示图像第一只是为了创造身体部位

(void)createEmail { 


NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:@"<html><body>"] retain]; 
    [emailBody appendString:@"<p>Some email body text can go here</p>"]; 
    UIImage *emailImage = [UIImage imageNamed:@"myImageName.png"]; 
    NSData *imageData = [NSData dataWithData:UIImagePNGRepresentation(emailImage)]; 

    NSString *base64String = [imageData base64EncodedString]; 
    [emailBody appendString:[NSString stringWithFormat:@"<p><b><img src='data:image/png;base64,%@'></b></p>",base64String]]; 
    [emailBody appendString:@"</body></html>"]; 
    NSLog(@"%@",emailBody); 

//mail composer window 
    MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init]; 
    emailDialog.mailComposeDelegate = self; 
    [emailDialog setSubject:@"My Inline Image Document"]; 
    [emailDialog setMessageBody:emailBody isHTML:YES]; 

    [self presentModalViewController:emailDialog animated:YES]; 
    [emailDialog release]; 
    [emailBody release]; 
} 

这显示在mfmailcomposeviewcontroller的默认行为here

+0

谢谢Alok,我刚刚在我的aEmail正文中添加了我的base64String代码,并且它的工作正常。 – Anki 2012-04-09 05:37:49

+0

有了这个imageData base64EncodedString,我能够在iPhone邮件详细信息中显示图像,但无法获取Gmail帐户中的图像,我该如何解决这个问题,任何建议? – Anki 2012-04-11 14:40:06

+0

其实我没有太多的知识呢 – 2012-04-12 07:05:22

相关问题