Sending Mail using MFMailComposeViewController in iPhone - iphone

I have a situation where i need to send details entered in the UITextfields to the administrator's mail ID without opening the MFMailComposeViewController.
This is a registration part of the application,so i will ask the users to enter their personal information like name,mail ID,DOB etc.,and i want to send these information as a mail to a hard coded ID which is the administrators mail ID.
I want this mail to be sent when the register button is pressed which is kept at the bottom of the same page.
I used the MFMailComposeViewController,without displaying the Composer view by avoiding the usage of this statement in order to prevent the modal view being popped up when i hit the register button
[self presentModalViewController:picker animated:YES]; and i use the
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error by invoking it using the statement
[self mailComposeController:picker didFinishWithResult:MFMailComposeResultSent error:nil];
where picker is the object of the MFMailComposeViewController
What should i do,to implement the same?
Kindly anybody advise me on how to achieve this.
Thanks a lot to everyone.

Thats not possible with MessageUI.framework. Instead you could set up a web service which sends the mail. Your app would connect to your server and sends the mail from there.

Related

Getting user's form data on iOS

I need to have my users fill out a form, and send me the information. Nothing fancy, just their name and email, and they'd be doing it willingly.
I looked into emailing the information to my account, but it seems like you have to pop the MFMailComposeViewController and let the user submit an email -- and I don't want to bother them with that.
I also tried a simple mailto url, like this:
NSString *url = #"mailto:example#example.com?&subject=Greetings from Cupertino!&body=Wish you were here!";
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
But it doesn't work on my simulator, or my iPhone, which is 4s with iOS 6.
I also looked into creating a google doc, and have the application send the user's info to its URL, but I'm assuming the result would be similar to the mailto URL?
So is there a good, simple way to do it?
So is there a good, simple way to do it?
Sure -- but not using mail. Use HTTP instead, and POST the data to a web server. If you need to collect the results by mail, you could easily create an e-mail message on the server and send from there, but it seems more likely that you'll just want to add the information to a database directly.
To use HTTP, you'll create a NSURLRequest with the relevant parameters and then send it using NSURLConnection. If you don't feel like digging into the URL loading system that iOS provides, there are a number of wrapper libraries that make it even easier. But for what you want to do, using NSURLConnection directly will be pretty straightforward.
Maybe you should have a look at these links :-
How to send mail from iphone app without showing MFMailComposeViewController?
Send mail without MFMailComposeViewController
Sending Email without using MFMailComposeViewController
MFMailComposer send email without presenting view

Get message body and recipients list from MFMessageComposeViewController

Is there a legal way to get body text and recipients list from MFMessageComposeViewController after SMS was sent(in didFinishWithResult callback delegate)?
I have an application which sends SMS and saves it in history. I'm using MFMessageComposeViewController for sending SMS. This is needed in order to save message correctly to history and perform searches.
I know there is no way to change body and recipients list after controller was shown, i want to get them.
I know there is phone's SMS history - but i need this in history of my application due to specific functionality of application according message body.
There is an official "legal" standard way to do this:
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult)result {
NSString *sms = controller.body;
Same with controller.recipients...

how to send email using UIbarbuttonitem without using MFMailComposerViewController

I want to send email using rightBarButtonItem without using MFMailComposerViewController.
Is It possible to send email using barButtonItem?
Any Idea how to do this?
thanx in advance.
You'll find a fantastic code sample on the accepted answer here to send a background email:
Locking the Fields in MFMailComposeViewController
All you need to do is setup your rightBarButtonItem's target to fire a method containing this email code, and then populate the message contents etc using the information you want to send.
Hope this helps!
Set an action method for the right bar button item and thus, you can make a direct call to open the email client and compose a mail.
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:#"mailto://testmailer#somemail.com"]];
This is just a quick fix or may be something you were looking for!

Checking SMS sending status iPhone

It's possible to check SMS sending status? e.g.
MFMessageComposeViewController * smsPicker = [[MFMessageComposeViewController alloc] init];
smsPicker.messageComposeDelegate = self;
smsPicker.body = #"Body";
[self presentModalViewController:smsPicker animated:YES];
[smsPicker release];
I don't know why, but the delegate
- (void)messageComposeViewController:(MFMessageComposeViewController *)controller didFinishWithResult:(MessageComposeResult) result; executing before sending and works if user cancelled SMS.
And I need to know, if SMS sent or failed (e.g. cell network error or something wrong). Thanks for future help!
You can use the result parameter messageComposeViewController:didFinishWithResult: to check the status of the message. Its type is MessageComposeResult:
enum MessageComposeResult {
MessageComposeResultCancelled,
MessageComposeResultSent,
MessageComposeResultFailed
};
Bear in mind that MessageComposeResultSent may only be interpreted as a successful queueing of the message for later sending. The actual send will occur when the device is able to send.
How can I check if device is able to send?
To test whether a device is capable of sending text messages, use MFMessageComposeViewController's canSendText class method. According to the documentation, you should always call this method before attempting to present the message compose view controller.
However, this will not tell you if the device is able to send the message now (in case you asked with this statement in mind: The actual send will occur when the device is able to send).
Unfortunately it does not account for cell network interruptions at the very least. For example when in airplane mode the delegate receives a MessageComposeResultSent!
I have filed a radar for this. Duplicating it may get the issue resolved sooner.

How to customize MFMailComposeViewController so that i can make the "to" field as non-editable?

I am using MFMailComposeViewController for sending feedback in my app. It works fine. But the problem here is, the user can edit/delete the "to" address. I want to make it as a non-editable one. May be, the user can add some mail addresses in "to" field.
But he/she should not delete the feedback address (Here, it is "support#xxxx.com").
Here is my code...
MFMailComposeViewController *composeWindow = [[MFMailComposeViewController alloc] init];
composeWindow.mailComposeDelegate = self;
NSString *str = #"Subject of the feedback";
[composeWindow setSubject:[str stringByAppendingString:[[UIDevice currentDevice]systemVersion]]];
NSArray *toRecipients = [NSArray arrayWithObject: #"support#xxxx.com"];
[composeWindow setToRecipients:toRecipients];
[self presentModalViewController:composeWindow animated:YES];
[composeWindow release];
Thanks in Advance
Rajkanth
You can not customize MFMailComposeViewController to avoid editing. Apple forbids this, and the reason is quite simple: it is the user and not you that must decide exactly what to send, to whom etc. The same applies for the UI controller allowing to send SMS (text) messages. And, of course, Apple does not allows sending an email or SMS without explicit interaction with the user. It is the user that must validate and send the email or SMS message. The validation process include the ability to cancel the message or to change any single property at will, including the "to" recipients.
All the other answers are correct. You can not change the interface of the MFMailComposeViewController. But you have other possibilities. ;-)
Three20 SDK includes also an Mail Composer. Try it out. I think it should be that far changeable, that the "to" field is not editable anymore.
I hope my answer is helpful for you.
Sandro Meier
EDIT
Three20 SDK was discontinued a while ago. So you shouldn't use it anymore for new projects. I advise you to use NimbusKit instead. This is also recommended by the Three20 SDK team. Sadly it does not include a MailComposeViewController
From the Apple documentation:
Important: The mail composition interface itself is not customizable and must not be modified by your application. In addition, after presenting the interface, your application is not allowed to make further changes to the email content. The user may still edit the content using the interface, but programmatic changes are ignored. Thus, you must set the values of content fields before presenting the interface.