I am developing an experiment in Unity engine (3.4) , it is supposed to run on iPad (iOS5). I do most of my scripting in Monodevelop (2.4.2). After the experiment is over, the results are saved in a text file and stored within the program. I can access them via synchronizing with iTunes, but i want to implement an extra feature - i want to be able to send the file via e-mail. For the starters, the e-mail address can be hardwired into the program.
What i need to implement is as follows:
If the participant in finished:
close the file
compose the message using the hardwired address and the file
check if the ipad has access to the internet
if yes - send the message and place it in the 'sent' of my mail app.
if no - place the message into the outbox of my mail app.
I have experience with GUI and IO scripting, but i have hardly dealt with networking in any programming language, i have no idea where to start. Unity API and Unity Answers were not very helpful.
If you have any useful links or bits of code I could learn from, i would greatly appreciate it.
you can use the MFMailComposeViewController and attach you data as NSData like this
if ([MFMailComposeViewController canSendMail])
{
MFMailComposeViewController *controller=[[MFMailComposeViewController alloc]init];
controller.mailComposeDelegate=self;
[controller setToRecipients#"..."];
[controller setSubject:#"Your Subject"];
NSData* attachmentData = ...
[controller addAttachmentData:attachmentData mimeType:#"..." fileName:#"..."];
[self presentModalViewController:controller animated:YES];
[controller release];
}
and dont forget to implement the delegate to dismiss the modal mail view controller
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[self dismissModalViewControllerAnimated:YES];
}
the user needs to have the mail app to be configured and press manually the send button
Related
This question already has answers here:
How to send mail from iphone app without showing MFMailComposeViewController?
(2 answers)
Closed 5 years ago.
I want to make it so that when my app's user types their email address into my UITextField, tapping the "complete purchase" button will automatically send an email populated with certain details to the address they input. This seems like it should be simple enough, however I can't seem to get it to work without popping open the Apple Mail client? Right now, I have the following code in place:
ViewController.m
- (void)sendProgram {
if([MFMailComposeViewController canSendMail]) {
MFMailComposeViewController *mailCont = [[MFMailComposeViewController alloc] init];
mailCont.mailComposeDelegate = self; // Required to invoke mailComposeController when send
[mailCont setSubject:#"Your Purchase!"];
[mailCont setToRecipients:[NSArray arrayWithObject:#"brittany#test.ca"]];
[mailCont setMessageBody:#"Here is the program you ordered! Please click the following link to download." isHTML:NO];
[self presentViewController:mailCont animated:YES completion:nil];
}
}
And technically, once the mail client pops open with all of these details filled in, all I have to do is hit the send button. However I want this information to be sent without the mail client ever opening. Is this possible?
You cant send mail in iOS app without opening MFMailComposeViewController. Apple does not provide any Framework for such thing. If you want to do this then you will have to use API. Server (API) will send mail to the recipients.
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init];
controller.mailComposeDelegate = self;
[controller setToRecipients:[NSArray arrayWithObject:#"sales#info.com"]];
[controller setSubject:#""];
[controller setMessageBody:self.messageText.text isHTML:NO];
[self presentViewController:controller animated:YES completion:nil];
Here I'm getting MFMailComposeViewController for sending mail, but I don't want use the MFMailComposeViewController while sending mail, directly send to receipent
message has already stored in "messageText.text" when click send button getting mvc
You can't do this with MFMailComposeViewController. Apple is very specific in the docs that sending email is under the users control, not your apps. You are sending email from the users account, you can understand why access to the email is restricted In this way(Here Explained Well).
There is a ways to achive it via many Webservices .
There is a project on google code to send messages through SMTP : skpsmtpmessage
Take a look at here for the Tutorial
Take a look at this code snippet. You might require this framework: https://code.google.com/p/skpsmtpmessage/
I've been looking around for a framework to simply allow me to send an email from inside my app. I have tried MailCore, Pantomime and SKPSMTP all with no luck. I can't get them to compile in Xcode, so I presumed they were outdated. Is there any way I can do this? If so, how? Thanks.
You can easily send emails from your iOS device. No need to implement SMTP and all. Best thing about using inbuilt emailing facilities in iOS is it gives you access to the address book! So it auto-completes names, email addresses. Yaaiiii!!
Include, AddressBook,AddressBookUI and MessageUI frameworks and code something like this. Note you can even choose to send content as HTML too!
#import <MessageUI/MessageUI.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
MFMailComposeViewController *mailComposer;
mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
[mailComposer setSubject:#"your custom subject"];
[mailComposer setMessageBody:#"your custom body content" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
For the sake of completeness, I have to write this selector to dismiss the email window if the user presses cancel or send -
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
if(error) NSLog(#"ERROR - mailComposeController: %#", [error localizedDescription]);
[self dismissModalViewControllerAnimated:YES];
return;
}
Happy coding...
It should be noted that MFMailComposeViewController has a method called canSendMail. If you don't check this before presenting a MFMailComposeViewController on a device that doesn't have an email account, you'll get a SIGABRT.
It's easy to miss this when testing on the device or the simulator since you'll probably have an email account on your Mac and your iPad.
SKPSMTPMessage still works fine for sending emails without the need for a UI
.
Make sure you add a reference to the CFNetwork.framework in your project. Otherwise you will get build errors.
I would imagine the Apple Approved way of doing this would be to send the data to a server via HTTP Post, and have the server generate the mail for you. I've seen others asking similar questions to this, and the answer is that if you send it from the device, you really need to prompt the user.
I can even tell you why this is: Imagine an application that could send itself to everyone in your address book without the your confirmation, telling them that you just installed application X, and they should too. Even if well intentioned, this could quickly create a huge SMTP storm, and in essence this would be the "I love you" virus.
That was enough of a strain on the public internet, but on wireless carriers, could quickly cause enough overload to block cel service.
Conclusion: Either use the ComposeViewController as #Srikar suggests, or else POST the data to your server, and send it from there.
I've been looking around for a framework to simply allow me to send an email from inside my app. I have tried MailCore, Pantomime and SKPSMTP all with no luck. I can't get them to compile in Xcode, so I presumed they were outdated. Is there any way I can do this? If so, how? Thanks.
You can easily send emails from your iOS device. No need to implement SMTP and all. Best thing about using inbuilt emailing facilities in iOS is it gives you access to the address book! So it auto-completes names, email addresses. Yaaiiii!!
Include, AddressBook,AddressBookUI and MessageUI frameworks and code something like this. Note you can even choose to send content as HTML too!
#import <MessageUI/MessageUI.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>
MFMailComposeViewController *mailComposer;
mailComposer = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
[mailComposer setSubject:#"your custom subject"];
[mailComposer setMessageBody:#"your custom body content" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];
For the sake of completeness, I have to write this selector to dismiss the email window if the user presses cancel or send -
- (void)mailComposeController:(MFMailComposeViewController*)controller
didFinishWithResult:(MFMailComposeResult)result
error:(NSError*)error
{
if(error) NSLog(#"ERROR - mailComposeController: %#", [error localizedDescription]);
[self dismissModalViewControllerAnimated:YES];
return;
}
Happy coding...
It should be noted that MFMailComposeViewController has a method called canSendMail. If you don't check this before presenting a MFMailComposeViewController on a device that doesn't have an email account, you'll get a SIGABRT.
It's easy to miss this when testing on the device or the simulator since you'll probably have an email account on your Mac and your iPad.
SKPSMTPMessage still works fine for sending emails without the need for a UI
.
Make sure you add a reference to the CFNetwork.framework in your project. Otherwise you will get build errors.
I would imagine the Apple Approved way of doing this would be to send the data to a server via HTTP Post, and have the server generate the mail for you. I've seen others asking similar questions to this, and the answer is that if you send it from the device, you really need to prompt the user.
I can even tell you why this is: Imagine an application that could send itself to everyone in your address book without the your confirmation, telling them that you just installed application X, and they should too. Even if well intentioned, this could quickly create a huge SMTP storm, and in essence this would be the "I love you" virus.
That was enough of a strain on the public internet, but on wireless carriers, could quickly cause enough overload to block cel service.
Conclusion: Either use the ComposeViewController as #Srikar suggests, or else POST the data to your server, and send it from there.
I am working on a simple application in which I need send sms programmatically to my friends.
so write below code for sending sms .
MFMessageComposeViewController *picker = [[[MFMessageComposeViewController alloc] init]autorelease];
if([MFMessageComposeViewController canSendText])
{
picker.messageComposeDelegate = self;
picker.recipients =[NSArray arrayWithObject:#"123"];
picker.body=#"hello";
[self presentModalViewController:picker animated:YES];
}
but I do not want to load message picker and send sms to friends.
// [self presentModalViewController:picker animated:YES];
is it possible to send sms without click in send button.
The two options available in the iOS API are:
MFMessageComposeViewController - requires user confirmation
sms:// URLs - requires user confirmation
If you want to do something else, you'll need to set up a network-based service with an SMS gateway provider and send messages via that. I used to work with such a provider that had an HTTP POST interface, which would be simple enough to use. That comes with a couple of important differences:
the SMS is actually sent by the gateway server, not the handset (though you can usually rewrite the sender ID and get the message billed to the handset owner)
you'll need to pay for access to the service, which might include paying per message (or more likely per 1,000 messages)
Also note that sending SMS on your users' behalf without confirmation might be frowned upon when your app is reviewed, especially if they're billed for.