0

我想在不显示 MFMailComposeViewController 的情况下发送电子邮件。我只想将电子邮件发送到一些电子邮件序列(因此用户应该只看到我的微调器,而不是带有发送按钮的 MFMailComposeViewController)。

我知道发送电子邮件的唯一方法是:(但这不是我想要的)

-(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]];
}

如何在没有 MFMailComposeViewController 的附加屏幕的情况下发送电子邮件?

先感谢您!

4

3 回答 3

1

您可以创建PHP 脚本来发送电子邮件,并可以使用从设备传递的 To、Message、Subject 调用 php 服务调用,

于 2012-12-13T06:07:01.730 回答
1

您可以通过 Web 服务来实现。编写一个 Web 服务,将邮件正文和收件人的电子邮件地址、主题等作为参数并从后端发送邮件。

于 2012-12-13T06:07:54.407 回答
1

Apple 没有提供任何 API 可以让您在没有用户交互的情况下发送电子邮件。

于 2012-12-13T06:14:39.863 回答