I am making a window based application. In this I have put some entries which become record for one person now I have put mailcomposer to send mail but I want to send the record in mail of that person in attachment automatically. Can I set document or excel file in mailcomposer in iphone application.
If anyone know please help me.
Thanks alot.
The MFMailComposeViewController protocol defines the method you need. Using the method
- (void)addAttachmentData:(NSData *)attachment mimeType:(NSString *)mimeType fileName:(NSString *)filename __OSX_AVAILABLE_STARTING(__MAC_NA,__IPHONE_3_0);
you can easily add any kind of file as an attachment to the mail. The easiest way would be to combine the records you stored in an CSV string and store data inside ass attachment. See below for an example:
MFMailComposeViewController *picker = [[[MFMailComposeViewController alloc] init] autorelease];
[picker setSubject:#"New Contacts"];
NSMutableString *body = [[NSMutableString alloc] init];
[body appendString:#"Hi, see attachment\n\n"];
NSMutableString *csv = [[NSMutableString alloc] init];
// Add data to csv
// ...
[picker addAttachmentData:[csv dataUsingEncoding:NSStringEncodingConversionExternalRepresentation allowLossyConversion:NO]
mimeType:#"text/csv"
fileName: #"contacts.csv"];
Related
I have this piece of code for MFMailComposer working fine in the simulator and iPhone 4, but it crashes on 3GS. What is the reason and what is the way to resolve it?
I checked it with breakpoints. mailPicker is not allocated with memory.
MFMailComposeViewController *mailPicker = [[MFMailComposeViewController alloc] init];
mailPicker.mailComposeDelegate = self;
// Set the subject of email
[mailPicker setSubject:#"Somebody got place in my sh*t list"];
NSString *emailBody = #"I just added somebody to my s**t list";
// This is not an HTML formatted email
[mailPicker setMessageBody:emailBody isHTML:NO];
// Create NSData object as PNG image data from camera image
NSData *data = UIImagePNGRepresentation([self captureScreen]);
// Attach image data to the email
// 'CameraImage.png' is the file name that will be attached to the email
[mailPicker addAttachmentData:data mimeType:#"image/png" fileName:#"CameraImage"];
// Show email view
[self presentModalViewController:mailPicker animated:YES];
// Release picker
[mailPicker release];
If at least one email account is enabled on the device, the following call should return YES:
[MFMailComposeViewController canSendMail]
Conversely, if all accounts are disabled/removed, it will return NO.
In my iPhone app, I have a view where I am showing the names of files stored in the Documents directory.
These files are downloaded from a server, and now I want to implement an email function into my application.
My questions are:
Can I attach more than one file, and if so, what is yhe maximum number of files that can be attached?
When I attach a file, do I have to give the location where it is stored?
Assuming you're using the stock MFMailComposeViewController, you can add more than one attachment using addAttachmentData:mimeType:fileName:. You have to attach the raw data, so you'll need to fetch the file from disk and get an NSData representation. Here's an example of how to add to add a UIImage as an attachment:
MFMailComposeViewController *mvc = [[MFMailComposeViewController alloc] init];
mvc.mailComposeDelegate = self;
[mvc setSubject:#"My Subject"];
[mvc setMessageBody:#"My Message Body" isHTML:NO];
NSData *imageData = UIImageJPEGRepresentation(myImage, 1);
[mvc addAttachmentData:imageData mimeType:#"image/jpeg" fileName:#"image.jpg"];
[self presentModalViewController:mvc animated:YES];
[mvc release];
I usually use the below code to allow the user to submit feedback on my apps. However for some reason in my OpenGL app the below code has a problem. It opens the email form correctly, however the form is locked - i.e the user can't actually edit the body of the text. Can anybody spot why this is happening ?
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Feedback on Stop That Bomb Free !"];
NSArray *toRecipients = [NSArray arrayWithObject:#"anemail#gmail.com"];
[picker setToRecipients:toRecipients];
// Fill out the email body text
NSString *emailBody =
[NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
[picker setMessageBody:emailBody isHTML:YES];
picker.navigationBar.barStyle = UIBarStyleBlack;
[inputController presentModalViewController:picker animated:YES];
[picker release];
From reading your code I can find some things you should change:
Replace:
NSString *emailBody = [NSString stringWithFormat:#"Hi Martin, I would like to make the following comment : "];
With:
NSString *emailBody = #"Hi Martin, I would like to make the following comment : ";
As you are not using any formatting; you dont need to call the class method to create the simple string.
The other thing you can change is the fact that you message does not contain HTML.
So you dont need isHTML:YES.
I have tested this successfully on a sample app.
I imagine the problem is with the view controller presenting the view, rather than the messageUI view.
I'm trying to make an iPhone app where a user can use a built-in template for sending SMS messages. For example:
Dear [recipient name]
I would like to meet you.
Yours sincerely,
[recipient name]
I want to change [recipient name] to the person the user is sending the SMS message to.
How would I generate the string to be sent in the SMS message, and how would I send it?
if any one looking for the code i have done it myself.
if (appdelegate.dataarray.count>0) {
NSMutableArray *dataarrrr = [appdelegate.dataarray objectAtIndex:0];
NSLog(#"%#",[dataarrrr objectAtIndex:0]);
NSString *aa = [dataarrrr objectAtIndex:0];
NSMutableArray *myArray = [aa componentsSeparatedByString:#","];
NSString *n = [myArray objectAtIndex:0];
NSString *m=[myArray objectAtIndex:1];
NSString *Message = [dataarrrr objectAtIndex:1];
NSString *new = [Message stringByReplacingOccurrencesOfString: #"<Dear User>" withString:n];
controller.body = new;
controller.recipients= [NSArray arrayWithObject:m];
controller.messageComposeDelegate = self;
[self presentModalViewController:controller animated:YES];
}
See the MFMessageComposeViewController, you can set the SMS body before displaying the message composer. I don’t think there’s a better way to send text messages, see this related question.
I'd like to send a text outline via email using MFMailComposeViewController. I'm currently doing this by creating a HTML version of the document and setting this as the body of the message.This works fine when viewing the email in MFMailComposeViewController, but on the receiving end (MobileMail.app, GMail Webinterface, OSX Mail.app) the formatting is lost.
This is my current code:
- (IBAction)showMailController {
if (![MFMailComposeViewController canSendMail]) return;
MFMailComposeViewController *mailComposeViewController = [[MFMailComposeViewController alloc] init];
mailComposeViewController.mailComposeDelegate = self;
NSString *stringRepresentation = #"<html><head></head><body><ul><li>#grocery</li><ul><li>Milk</li><li>Cat food</li><li>Rice</li><li>Tofu</li></ul></ul></body></html>";
[mailComposeViewController setMessageBody:stringRepresentation isHTML:YES];
[self presentModalViewController:mailComposeViewController animated:YES];
[mailComposeViewController release];
}
Am I doing something wrong? Is there an other way to do it?
I also tried exporting as simple text outline with manually indenting (I inserted two spaces as tab didn't work), but text editors don't recognize this as an outline.
NSMutableString *inset = [[NSMutableString alloc] init];
NSUInteger i;
for (i=0; i<insetCount;i++) {
[inset appendString:#" "];
}
NSMutableString *string = [[NSMutableString alloc] initWithString: [NSString stringWithFormat:#"%#%C ", inset, 0x2022]];
Thank you for your help!
In my apps, I only put what is in between the body tags, i.e. NO
html
head
body
tags. Just put the stuff you would normally put in between the body tags and it should work.