send an HTML formatted email using MFMailComposeViewController - iphone

I am formatting a mail with HTML content and sending it using MFMailComposeViewController.But on the receiver side mail is not reaching in HTML format.Only Plain text is visible.How could I resolve this issue.Thanks in advance.

Be sure to set the message body using the following lines:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
NSString *emailBody = #"<p><b>Hello World</b></p>";
[picker setMessageBody:emailBody isHTML:YES];

Even if you set isHTML param to YES, your message body can be sent as plain/text if the message body can be represented as such.
In my case adding a link in the message body helped. Bold formatting with tags works too. Tricky!
Tested on iPod 1G 3.1.3.

Related

How to link the text field with my email in my app?

How can I send the information that the user inset in text field UITextField to my email?
and how can I let the information page shows once, only at the first time the user enters the app?
What you're asking is vague, but to take the data entered into a textfield and put it in a string just use:
NSString *theEmailBody = theTextField.text;
From there you can send an email using the standard Apple email framework:
MFMailComposeViewController *mail =[[MFMailComposeViewController alloc] init];
NSString *theEmailbody = theTextField.text;;
[mail setMessageBody:theEmailbody isHTML:NO];
or by making your own mail server and sending the HTTP request there.
You can use the following code in you function to send email.
MFMailComposeViewController *mail =[[MFMailComposeViewController alloc] init];
NSString *emailbody = textField.text;;
[mail setMessageBody:emailbody isHTML:NO];
Apple has sample code to show you how to set up in app email (linked below)
After you've done this, you can easily change (for example) the body of your email to be the contents of your textField by adding this where appropriate.
NSString *emailBody = myTextField.text;
Then additionally, if you wish for the information page to only be visible the first time the app is launched, look into NSUserDefaults. This will allow you to store and retrieve a value to let the app know wether or not to load your information page.
https://developer.apple.com/library/ios/#samplecode/MailComposer/Introduction/Intro.html#//apple_ref/doc/uid/DTS40008865

Attachments using email uri scheme in iOS

I am implementing an iphone application (iOS 4.2) from where I would like to trigger the email client to send messages with attachments. I could effectively use uri schemes in combination with the class NSURL in order to trigger the email app but I was wondering whether it is possible to attach images. I have tried with mailto:whoever#wherever.org?subject=sthg&body=sthgelse&attachment=/path/to/file but the attachments are not included. I know iphone applications are sandboxed therefore it is possible that the email utility were not able to access the path to my image since it is located in my application bundle. On the other hand I was considering to administer my images with the photo manager. (1) Is there a way to include attachments in this way? (2) If so, is it possible to reference images either from my app or from the photo client? I could not find any attachments argument in the mailto RFC but maybe Apple has provided some way to achieve this.
Thanks in advance for your help,
Luis
MFMailComposeViewController will be able to do that, some example of usage belows:
remember to add MessageUI.framework
MFMailComposeViewController *email = [[MFMailComposeViewController alloc] init];
email.mailComposeDelegate = self;
[email setSubject:#"Whatever"];
// Set up recipients
NSArray recipients = [NSArray arrayWithObject:#"whoever#wherever.org"];
[email setToRecipients:recipients];
// Attach an image to the email
UIImage *attachment = ...;
NSData *data = UIImagePNGRepresentation(attachment);
[email addAttachmentData:myData mimeType:#"image/png" fileName:#"ok.png"];
// Fill out the email body text
NSString *emailBody = #"test mail";
[email setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[email release];
Instead of using the mailto: URL scheme, you should use the MFMailComposeViewController which allows you to add attachments. It also has the added benefit that using will not leave your app.
If one does not have account MFMailComposeViewController simply crashes.
Yes, you can call canSendMail first with the result NO(!), what next?
The answer is - use 'mailto:'. It'll popup dialog to create account.

Email body not displayed after sending from iPhone via code

I have couple of iPhone apps that sends an email via code.
I've noticed quite a number of emails coming in from customers where everything is populated except for the body message (i always see their signature though).
I sent a test message, using the same app from my iPhone device, and i get the message (a simple "this is a test" message).
Wondering if there are any coding that needs to occur to handle different version of iOS, or perhaps different iPhone device hardwares?
Anybody noticed this before?
I would consider the possibility that the users are accidentally pressing send on a blank email. Perhaps to eliminate this as a possibility, guard against blank messages in code, then if it still happens you'll know it's a real issue.
set all delegates properly
and use this
MFMailComposeViewController *controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
NSString *sub= [NSString stringWithFormat:#"The Black Sheep App: %# Specials",[[BarSplArr objectAtIndex:0]objectForKey:#"barname"]];
NSString *message=[NSString stringWithFormat:#"Check out these specials for %# on %#, %# \n\n %#",[[BarSplArr objectAtIndex:0]objectForKey:#"barname"],day,date,[[BarSplArr objectAtIndex:0]objectForKey:#"drinkspecials"] ];
[controller setSubject:sub];
[controller setMessageBody:message isHTML:NO];
[self presentModalViewController:controller animated:YES];
[controller release];

MFMailComposeViewController adds null Content-Id

This is my first post to the group so please be kind :)
I am sending a couple of audio attachments from my app as follows:
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
picker.modalPresentationStyle = UIModalPresentationCurrentContext;
[picker setSubject:#"Test message"];
NSArray *toRecipients = [NSArray arrayWithObject:#"foo#bar.com"];
[picker setToRecipients:toRecipients];
// multiple attachments are made as follows
NSData *myData = [NSData dataWithContentsOfFile:filePath];
[picker addAttachmentData:myData mimeType:#"audio/x-caf" fileName:fileName];
[picker setMessageBody:#"test message" isHTML:NO];
[controller presentModalViewController:picker animated:YES];
A mailComposeController method takes care of dismissing the modal view.
Unfortunately, when the message is delivered the mime headers for the attachments land up having the Content-Id set to null. Here is what it looks like:
Content-Type: audio/x-caf; name="audio_1.caf"
Content-Transfer-Encoding: base64
Content-Id: <(null)>
Content-Disposition: attachment; filename="audio_1.caf"
If I manually delete the Content-Id field and reload the message in my Mac Mail program (Mail Version 3.6) the attachments show up correctly. In other words, I don't really need/want theContent-Id to be inserted in the mime header.
Also, its worth mentioning that for debugging purposes if I set the mime type to "image/jpeg" the mime header does get a valid Content-Id string. All my attachments show up in Mail. As is to be expected, in that case the attachments don't open correctly on the Mac or iPhone.
Any help would be greatly appreciated.
thanks,
apurva
According to this post, you cannot manually set the Content-ID
How to add a UIImage in MailComposer Sheet of MFMailComposeViewController
OK. Figured it out -- more by accident than anything else.
The null content ids seem to be inserted by the mail server (not my app or MFMailComposeViewController).
Initially I was testing the send with a personal yahoo account. Thats when I ran into the problem. When I switched to my work account the problem disappeared.
thanks,
apurva

Easy way to open the Mail application with an pre-defined message subject and body?

In my app the user generates text content. I want to enable the user to launch the Mail application, which then should contain a specified subject and message body. Like: You write a poem in my app and then want to send it to your new girlfriend. So you tap a mail icon and the Mail app opens, containing already an subject and message body with your poem inside.
Someone said there is a kind of URL mechanism for that?
You can use MFMailComposeViewController for sending the mail.
-(void)OpenMail{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;
[picker setSubject:#"my new poem"];
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
emailBody is string which contains the poem.
All the best.
Apple URL Scheme Reference: Mail Links lists all your options.
Or you use MFMailComposeViewController.