Sending an image in a faceless email - iphone

I am trying to send a faceless email (sending an email without showing the interface), using the code below.
I also want to attach an image to this email.
Is this possible?
- (void) sendEmailTo:(NSString *)toStr withSubject:(NSString *)subjectStr withBody:(NSString *)bodyStr
{
NSString *emailString=[[NSString alloc] initWithFormat:#"mailto:?to=%#&subject=%#&body=%#",
[toStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[subjectStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding],
[bodyStr stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:emailString]];
[emailString release];
}

You are unable to send faceless emails using the built-in emailer.
However you should be able to roll your own emailer using parts from email frameworks like for instance Pantomime

Related

Direct Email to userid

I'm trying to send an email to a X person with some details in the app.
I'm using the following code. I don't want to use the MessageUI because I want to send mail directly without showing the mail composer.
NSString *url = [NSString stringWithFormat:#"mailto:pradeep#gmail.com?&subject=Results&body=Check Out your Results here=%#",score];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: [url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]];
But it fails with EXEC_BAD_ACCESS. Can anyone let me know how to solve it?
You can't send the mail without the mail composer. The way you are trying to do it will open the mail app and show the user the mail filed in with all the detail give in the mail link.
The only way to do what you want it to either have a webservice which handels the mail of implement SMTP in your app. You will need ask to user for there SMTP setting so a webservice might be the best way.

iPhone MFMailComposeViewController

I have to send an email in one of the application,i have implement MFMailComposeViewController and everything is working fine, mail can be send and received also.
However my main issue is that, is it possible to send mail without opening the Sheet of MFMailComposeViewController ?
Means in my application I have to pass on url into suject field and have to type the recepients name in textfield, so is it that we cannot open the sheet of messagecontroller window and send the mail from the uibarbutton integration?
plz let me know that
If you dont want to use MFMailComposer, you may use following code.You have to handle you textfield's mail id's through string manipulation and append it in mString before body.you may use UItextview for body.
NSString *mString = #"mailto:foo#example.com?cc=bar#example.com&subject=Greetings%20from%20Cupertino!&body=Wish%20you%20were%20here!";
NSString *url = [NSString stringWithString:mString];
[[UIApplication sharedApplication] openURL: [NSURL URLWithString: url]];
To prevent spam from using the user mailbox, application cannot send mail automatically. THe user will have to press "Send" themselves. This way, they know what e-mail is going out.
If you want your app to automatically send mail, you will have to setup your own SMTP client/server.

sending sms and email through program automatically

I have read that In App SMS is finally supported in iPhone OS 4...look at
here
I want to know that if it is also possible to send emails automatically without user's intraction if yes then how?.I mean while our application is running.
No, that's not possible with the official iPhone SDK.
You have to use MFMailComposeViewController or [[UIApplication sharedApplication] openURL: #"sms:12345678"]; or send a text.
Here is the code for Email
NSString *recipients=[NSString stringWithFormat:#"mailto:ABC#gmail.com?cc=bcd#gmail.com&subject=Hi"];
NSString *body=[NSString stringWithFormat:#"&body=How r u "];
NSString *email=[NSString stringWithFormat:#"%#%#",recipients,body];
email=[email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];

When will [MFMailComposeViewController canSendMail] return NO

My iPhone app is using the MFMailComposeViewController class to send an in-app email with an attachment.
The app will only attempt to display the mail composer dialog if the "canSendMail" method of class MFMailComposeViewController returns true (YES). Specifically, if the following method returns YES, it shows the mail composer, otherwise the user is presented with an error alert dialog stating that there are no email accounts set up on the device:
- (BOOL)canDeviceSendEmail
{
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
return mailClass != nil && [mailClass canSendMail];
}
A team of testers have reported that they get this error alert dialog, even when email accounts are set up on the device. The tester used an iPhone 3G with OS 3.1.3. Therefore the MFMailComposeViewController class must have existed, and the "canSendMail" method must have returned NO.
My question is therefore: apart from the case when there are no email accounts set up on the device, in what other circumstances can the "canSendMail" method return NO?
~ Thanks
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.
For +canSendMail to return YES the default account must be set-up for sending emails.
(Internally, +[MFMailComposeViewController canSendMail] calls +[MailAccountProxy defaultMailAccountForDelivery], which finds the first mail account being -isDefaultDeliveryAccount.)
In addition to an email account not being setup on a device, canSendMail also returns NO when an MDM profile is installed and configured to not allow third party apps to send mail. In this case you must use openURL: with a mailto: URL in order to launch Mail.app and optionally fill in the to, cc, bcc, subject, and body field.
mailto: RFC
https://www.rfc-editor.org/rfc/rfc2368
This worked for me.
In Device Go setting->Mail,Contacts,Calendar->Accounts
Here you can see no account is added.Now add account now go back to your app and you can find its returning yes this time and you are able to send E-mail.
Thanks
[MFMailComposeViewController canSendMail] will return NO when you don't have any mail account on device. In this case you can open mail app by the following code:
- (void)openMailApp {
NSString *recipients = #"mailto:?cc=&subject=";
NSString *body = #"&body=";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, body];
email = [email stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
In case of iOS 10.1, you can enable mail from iCloud first (in Settings). Then sign in to your iCloud account. All the contacts and email should be available in your simulator after those changes.
With the change, I can get true from:
MFMailComposeViewController.canSendMail()
I am using Xcode 8.1 with Swift 3.
Vladimir's answer without deprecated functions:
NSString *recipients = #"mailto:testingEmail#example.com?subject=emailsubject";
NSString *body = #"&body=body:";
NSString *email = [NSString stringWithFormat:#"%#%#", recipients, body];
email = [email stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLFragmentAllowedCharacterSet]];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email] options:#{} completionHandler:^(BOOL success) {
}];
You can't be certain that MFMailComposeViewController must have existed because your method doesn't discriminate between MFMailComposeViewController not existing and [MFMailComposeViewController canSendMail] returning NO.
What iPhone OS you're testing on is not relevant; what version of the iPhone SDK your application links against is what determines whether MFMailComposeViewController will be available at runtime. If you want that class, you need to build with SDK 3.0 or later.
Did you include the Messaging Framework? I had a similar issue once and it was only because I forgot to add the correct framework to the XCode project.

how to send e-mail without MFMailComposeViewController in iOS?

How to redirect to mail application from iPhone application?
I have seen in Stack Overflow like MailComposerViewController.
They are sending email from within the iPhone application. But I want to quit project and redirect it to in-built Mail app Which is in iPhone?
How can I do this?
I have tried the following. Are there any frameworks required for this?
- (IBAction)ddd:(id)sender
{
NSString *_recipient = #"someone#email.com";
NSURL *_mailURL = [NSURL URLWithString:[NSString stringWithFormat:#"mailto:%#?subject=My Subject", _recipient]];
[[UIApplication sharedApplication] openURL:_mailURL];
}
No, there are plenty of stackoverflow posts on how to send e-mail without MFMailComposeViewController. In fact, there was at least one response to your request 16 hours earlier that would quit your app and start Mail
Here's how I do it in my apps, copied exactly as it is:
-(IBAction) mailForHelp:(id)sender
{
NSString *urlStr = [NSString stringWithFormat:#"mailto:info#BitsOnTheGo.com?subject=NumMemorize Question"];
NSURL* mailURL = [NSURL URLWithString:[urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
[[UIApplication sharedApplication] openURL: mailURL];
}