Text file appear as a small box in mail body in ios objective c -
i want send 2 attachments in mail. 1 image , text file. when send both attachment in single mail, text file appears square blank box. image , text file, both files received @ receiver side , readable. issue sender cannot see text file in mail body before sending mail. code sending mail given below.
- (void)showemail:(nsstring*)file { nsdateformatter *dateformatter = [[nsdateformatter alloc] init]; [dateformatter setdateformat:@"yyyy-mm-dd hh:mm:ss"]; nsdate *datefromstring = [dateformatter datefromstring:abc4]; [dateformatter setdateformat:@"mm/dd/yyyy"]; nsstring *titledate=[dateformatter stringfromdate:datefromstring]; nsstring *emailtitle = [nsstring stringwithformat:@"(%@)",titledate]; [dateformatter setdateformat:@"mm/dd/yyyy hh:mm:ss"]; nsstring *subjectdate=[dateformatter stringfromdate:datefromstring]; nsstring *messagebody = [nsstring stringwithformat:@"%@ %@",abc,subjectdate]; //nsarray *torecipents = [nsarray arraywithobject:self.txtfldemail.text]; mfmailcomposeviewcontroller *mc = [[mfmailcomposeviewcontroller alloc] init]; mc.mailcomposedelegate = self; [mc setsubject:emailtitle]; [mc setmessagebody:messagebody ishtml:no]; //[mc settorecipients:torecipents]; // determine file name , extension nsarray *filepart = [file componentsseparatedbystring:@"."]; nsstring *filename = [filepart objectatindex:0]; nsstring *extension = [filepart lastobject]; // resource path , read file using nsdata //nsstring *filepath = [[nsbundle mainbundle] pathforresource:filename oftype:extension]; //nsstring *xyz=[[nsuserdefaults standarduserdefaults]valueforkey:@"readpath"]; nsdata *filedata; nsdata *filedata1; if ([title isequaltostring:@"excel"]) { filedata = [nsdata datawithcontentsoffile:filepath]; nsstring *xyz=[[nsuserdefaults standarduserdefaults]valueforkey:@"commentfilelocation"]; filedata1=[nsdata datawithcontentsoffile:xyz]; nslog(@"filedata1>>%@",filedata1); } else if([title isequaltostring:@"screenshot"]) { nsstring *xyz=[[nsuserdefaults standarduserdefaults]valueforkey:@"readpath"]; filedata = [nsdata datawithcontentsoffile:xyz]; nsstring *xyz1=[[nsuserdefaults standarduserdefaults]valueforkey:@"commentfilelocation"]; nslog(@"xyz1>>%@",[[nsuserdefaults standarduserdefaults]valueforkey:@"commentfilelocation"]); filedata1=[nsdata datawithcontentsoffile:xyz1]; } // determine mime type nsstring *mimetype; if ([extension isequaltostring:@"jpg"]) { mimetype = @"image/jpeg"; } else if ([extension isequaltostring:@"png"]) { mimetype = @"image/png"; } else if ([extension isequaltostring:@"doc"]) { mimetype = @"application/msword"; } else if ([extension isequaltostring:@"ppt"]) { mimetype = @"application/vnd.ms-powerpoint"; } else if ([extension isequaltostring:@"html"]) { mimetype = @"text/html"; } else if ([extension isequaltostring:@"txt"]) { mimetype = @"text/html"; } else if ([extension isequaltostring:@"pdf"]) { mimetype = @"application/pdf"; } else if ([extension isequaltostring:@"csv"]) { mimetype = @"text/csv"; } nsstring *mimetype1; if ([extension isequaltostring:@"jpg"]) { mimetype1 = @"image/jpeg"; } else if ([extension isequaltostring:@"png"]) { mimetype1 = @"image/png"; } else if ([extension isequaltostring:@"doc"]) { mimetype1 = @"application/msword"; } else if ([extension isequaltostring:@"ppt"]) { mimetype1 = @"application/vnd.ms-powerpoint"; } else if ([extension isequaltostring:@"html"]) { mimetype1 = @"text/html"; }else if ([extension isequaltostring:@"txt"]) { mimetype1 = @"text/html"; }else if ([extension isequaltostring:@"pdf"]) { mimetype1 = @"application/pdf"; }else if ([extension isequaltostring:@"csv"]) { mimetype1 = @"text/csv"; } // add attachment [mc addattachmentdata:filedata mimetype:mimetype filename:file]; nsdateformatter *dateformatter1 = [[nsdateformatter alloc] init]; [dateformatter1 setdateformat:@"yyyy-mm-dd hh:mm:ss"]; nsdate *datefromstring1 = [dateformatter1 datefromstring:abc4]; [dateformatter1 setdateformat:@"mm.dd.yyyy"]; nsstring *titledate1=[dateformatter1 stringfromdate:datefromstring1]; nsstring *commentfilename=[nsstring stringwithformat:@"%@ %@ comments.txt",abc,titledate1]; [mc addattachmentdata:filedata1 mimetype:mimetype1 filename:commentfilename]; [![enter image description here][1]][1] // present mail view controller on screen [self presentviewcontroller:mc animated:yes completion:null]; } the screenshot of mail attached in question.
probably should try change mime type. did tryed use text/plain example? instead of
if ([extension isequaltostring:@"txt"]) { mimetype1 = @"text/html"; } 
Comments
Post a Comment