电子邮件问题:想要在没有其他窗口的情

时间:2012-12-13 06:02:16

标签: iphone email sendmail mfmailcomposeviewcontroller mfmailcomposer

我想在不显示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附加屏幕的情况下发送电子邮件?

提前谢谢!

3 个答案:

答案 0 :(得分:1)

您可以创建PHP script to send email并可以通过设备传递的To,Message,Subject调用php服务调用,

答案 1 :(得分:1)

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

答案 2 :(得分:1)

Apple没有提供允许您在没有用户互动的情况下发送电子邮件的API。