如何在电子邮件正文中的一些文本后设置第一个图像? [英] How to set first Image after Some Text in Email body?

查看:118
本文介绍了如何在电子邮件正文中的一些文本后设置第一个图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用MFMailComposeViewController发送电子邮件,

I am using MFMailComposeViewController for sending the Email,

使用这个代码我可以得到图像,但图像来自文本细节后
I wan't First Image and after Text,

With this code I am able to get the Image, But image comes after the Text Detail, I wan't First Image and after Text,

这是我的代码,

   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];

请任何机构建议我如何做?

Please any body suggest me How can i do that?

推荐答案

根据我的知识,这是mfmailcomposeviewcontroller的默认行为,而不是只是添加图像作为附件,你可以做如下显示图像第一只是创建身体部分



as of my knowledge this is the default behavior of the mfmailcomposeviewcontroller instead of just adding image as attachment you can do as below to show image first just to create body part

(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];
}

这显示为此处

这篇关于如何在电子邮件正文中的一些文本后设置第一个图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆