You can do it by Web services. Write a web service that takes message for Email body and receiver's email address, subject etc as parameters and sends mail from backend.
Email issue: want to send email without additional window
-
07-12-2021 - |
Question
I want to send email without showing MFMailComposeViewController. I just want to send email to some sequence of emails (so user should see only my spinner, not MFMailComposeViewController with send button).
The only way to send emails I know is: (but it's not I want)
-(void)showMessageController:(id)sender
{
Class mailClass = (NSClassFromString(@"MFMailComposeViewController"));
if (mailClass != nil)
{
// We must always check whether the current device is configured for sending emails
if ([mailClass canSendMail])
{
[self displayComposerSheet];
}
else
{
[self launchMailAppOnDevice];
}
}
else
{
[self launchMailAppOnDevice];
}
}
// Displays an email composition interface inside the application. Populates all the Mail fields.
-(void)displayComposerSheet
{
MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
[appDelegate setNavigationBarTextured:YES navigationBar:picker.navigationBar];
picker.mailComposeDelegate = self;
[picker setSubject:@"Please, look at my photo!"];
// Attach an image to the email (mydata - data of the image)
[picker addAttachmentData:myData mimeType:@"image/png" fileName:@"photo"];
// Fill out the email body text
NSString *emailBody = @"Hello!\nPlease, have a look at my photo!";
[picker setMessageBody:emailBody isHTML:NO];
[self presentModalViewController:picker animated:YES];
[picker release];
}
// Launches the Mail application on the device.
-(void)launchMailAppOnDevice
{
// NSString *recipients = @"mailto:first@example.com?cc=second@example.com,third@example.com&subject=Hello from California!";
NSString *recipients = @"mailto:subject=Please, look at my photo!";
NSString *body = @"&body=Hello!\nPlease, have a look at my photo!";
NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
}
How can I send email without additional screen of MFMailComposeViewController?
Thank you in advance!
Solution
OTHER TIPS
You can create PHP script to send email and can call the php service call with To, Message, Subject passed from device,
There is no API provided by Apple that would let you send emails without user interaction.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow