Email issue: want to send email without additional window

不羁的心 提交于 2019-12-13 04:42:29

问题


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!


回答1:


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.




回答2:


You can create PHP script to send email and can call the php service call with To, Message, Subject passed from device,




回答3:


There is no API provided by Apple that would let you send emails without user interaction.



来源:https://stackoverflow.com/questions/13853895/email-issue-want-to-send-email-without-additional-window

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!