Send outline as email using MFMailComposeViewController - iphone

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.

Related

MessageUI framework issue for UITextField contents are not displayed

I've included messageUI framework in my app for sending mail.It contains five UITextField where the values entered by user should be displayed in mail body. Here is my code
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *mailer = [[MFMailComposeViewController alloc] init];
mailer.mailComposeDelegate = self;
[mailer setSubject:[NSString stringWithFormat:#"Appointment From Mr/Mrs. %#",text1.text]];
NSArray *toRecipients = [NSArray arrayWithObjects:#"info#xxx.com", nil];
[mailer setToRecipients:toRecipients];
NSString *emailBody =[NSString stringWithFormat:#"Name :%#\nDate: %#\nPreferred Time Slot: %#\nE-Mail:%#\nSpecific Requests:",text1.text,text2.text,text3.text,text4.text,text5.text];
[mailer setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:mailer animated:YES];
[mailer release];
}
The issue i'm facing is that all the four text field values are displayed only the fifth text field values are not displayed..Any idea?...am i missing anything?...
You only have four %# in the form at string, thus the last parameter supplied to the format method is ignored.
Change the format string to have five parameters:
NSString *emailBody =[NSString stringWithFormat:#"Name :%#\nDate: %#\nPreferred Time Slot: %#\nE-Mail:%#\nSpecific Requests:%2",text1.text,text2.text,text3.text,text4.text,text5.text];
Edit the following line of code
NSString *emailBody =[NSString stringWithFormat:#"Name :%#\nDate: %#\nPreferred Time Slot: %#\nE-Mail:%#\nSpecific Requests:%#",text1.text,text2.text,text3.text,text4.text,text5.text];
you will get your requirements...Dont forget to use resignFirstresponder to hide keyboard after u entered text...

iPhone SMS Url Scheme with Body Content?

I am looking to pre-fill the SMS body with content given "smsto:555-555-5555:Hello World"
I have done my research and everybody says it cannot be done but I have a QR reader on my phone right now that can take "sms:555-555-5555:Hello world" and pre-fills the content with the correct phone number scanned.
So my question is. How do i do this? it is pretty clear that the URL scheme provided doesn't handle the body. What other methods are out there to pre-fill the body? it can clearly be done with the QuickMark Reader.
You can use the modalViewController for SMS to fill the body of a text.
add the MessageUI framework to your project.
set you viewController as the MFMessageComposeDelegate
Create the modal view and present it:
-(void) showMessageComposerWithText:(NSString*)messageText telNumber:(NSString*)telNumber composeDelegate:(id)delegate
{
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
if([MFMessageComposeViewController canSendText]){
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = delegate;
[delegate presentModalViewController:controller animated:YES];
}
}
You can't launch the Messages app with a predefined message according to Apple Documentation.
What you can do is implement the handling yourself and parse the URL like the following:
NSURL *url = /* the url you get from the web (in webview delegate) or after QR Code scan */;
if ([url.scheme isEqualToString:#"sms"]) // is it a sms ?
{
if([MFMessageComposeViewController canSendText]) // can I send text message ?
{
NSArray *parts = [url.absoluteString componentsSeparatedByString:#":"];
NSString *messageText = parts.count == 3 ? [parts objectAtIndex:2] : #"";
NSString *telNumber = parts.count >= 2 ? [parts objectAtIndex:1] : #"";
MFMessageComposeViewController *controller = [[MFMessageComposeViewController alloc] init];
controller.body = messageText;
controller.recipients = [NSArray arrayWithObject:telNumber];
controller.messageComposeDelegate = self;
[self presentViewController:controller animated:YES completion:nil];
[controller release];
}
}
And voilĂ  !

iOS Can I inject HTML code in the emails send by mail app?

We are running an stationery business and designing email stationeries, signatures etc for people. On PC there's no problem using those because it's easy to add HTML to the email contents in most of the mail clients. However, is this possible with iOS?
How are we doing that now for mobile devices is we tell users to add our SMTP server and send messages through it. How this SMTP works is it's wrapping each email with HTML before sending. I wonder if this can be done directly in iPhone with some kind of post-processing of emails before those are sent?
AFAIK you can't trap emails sent from the built in email client. You can however, write your own app that sends emails with HTML using the MFMailComposeViewController.
EDIT: Added some example code:
- (void) sendEventInEmail
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"Email Subject"];
// Fill out the email body text
NSString *iTunesLink = #"http://itunes.apple.com/gb/app/whats-on-reading/id347859140?mt=8"; // Link to iTune App link
NSString *content = [eventDictionary objectForKey:#"Description"];
NSString *imageURL = [eventDictionary objectForKey:#"Image URL"];
NSString *findOutMoreURL = [eventDictionary objectForKey:#"Link"];
NSString *emailBody = [NSString stringWithFormat:#"<br /> <a href = '%#'> <img src='%#' align=left style='margin:5px' /> </a> <b>%#</b> <br /><br />%# <br /><br />Sent using <a href = '%#'>What's On Reading</a> for the iPhone.</p>", findOutMoreURL, imageURL, emailSubject, content, iTunesLink];
[picker setMessageBody:emailBody isHTML:YES];
[self presentModalViewController:picker animated:YES];
[picker release];
}
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
// Notifies users about errors associated with the interface
switch (result)
{
case MFMailComposeResultCancelled:
break;
case MFMailComposeResultSaved:
break;
case MFMailComposeResultSent:
break;
case MFMailComposeResultFailed:
break;
default:
break;
}
[self dismissModalViewControllerAnimated:YES];
}
It should look somewhat like this:
// Compose body
NSMutableString *emailBody = [[[NSMutableString alloc] initWithString:#"<html><body>"] autorelease];
[emailBody appendString:#"<p>Hi<br><br>THis is some HTML</p>"];
[emailBody appendString:#"</body></html>"];
// Compose dialog
MFMailComposeViewController *emailDialog = [[MFMailComposeViewController alloc] init];
emailDialog.mailComposeDelegate = self;
[emailDialog setToRecipients:[NSArray arrayWithObject:#"test#test.com"]];
// Set subject
[emailDialog setSubject:#"I got a question!"];
// Set body
[emailDialog setMessageBody:emailBody isHTML:YES];
// Show mail
[self presentModalViewController:emailDialog animated:YES];
[emailDialog release];
As said above, don't forget the delegate 8)
HTH
Marcus
You can take the body text of their email and change it (by using stringWithFormat: or even an NSMutableString) to make it html. Using MFMailComposeViewController's -(void)setMessageBody:(NSString*)body isHTML:(BOOL)isHTML
Example:
NSString *bodyText = [[NSString alloc] initWithFormat:#"<html><p>%#</p></html", bodyField.text]; //Not an HTML expert
then send the email with the body being bodyText.
Using MFMailComposeViewController you can include HTML in the body of the email. Additionally, you can attach images. See these methods:
- (void)setMessageBody:(NSString*)body isHTML:(BOOL)isHTML
- (void)addAttachmentData:(NSData*)attachment mimeType:(NSString*)mimeType fileName:(NSString*)filename

attachment of file in compose mail in iphone

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

Problem with MFMailComposeViewController - User Can't Edit Mail Body - iPhone

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.