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

相關問題