如何在 iPhone 中填写电子邮件的“收件人”和“主题”?

发布于 2024-12-12 18:05:43 字数 76 浏览 0 评论 0原文

我的应用程序中有一个名为“联系我们”的按钮!有没有办法在 iPhone 中打开 Eamil 客户端,其中填入我提供的“收件人”和“主题”?

I have a button in my app called contact Us! Is there a way to open up the Eamil client in iPhone filled with To and Subject that I provide?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

请恋爱 2024-12-19 18:05:43

您将需要使用 MFMailComposeViewController 类。以下是苹果 MailComposer 示例

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Hello from California!"];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
[picker setToRecipients:toRecipients];

[self presentModalViewController:picker animated:YES];
[picker release];

: MailComposer 示例还向您展示了如何打开外部邮件应用程序:

NSString *recipients = @"mailto:[email protected]&subject=Hello from California!";
NSString *body = @"&body=It is raining in sunny California!";

NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];

You will want to use the MFMailComposeViewController class. Here's the relevant part from Apple's MailComposer example:

MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
picker.mailComposeDelegate = self;

[picker setSubject:@"Hello from California!"];

// Set up recipients
NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
[picker setToRecipients:toRecipients];

[self presentModalViewController:picker animated:YES];
[picker release];

The MailComposer sample also shows you how to open the external mail app:

NSString *recipients = @"mailto:[email protected]&subject=Hello from California!";
NSString *body = @"&body=It is raining in sunny California!";

NSString *email = [NSString stringWithFormat:@"%@%@", recipients, body];
email = [email stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:email]];
白馒头 2024-12-19 18:05:43

查看 MFMailComposeViewController。您可以设置主题、收件人字段,甚至可以使用 HTML 填充正文。

Check out MFMailComposeViewController. You can set the Subject, To Field, and even populate the body with HTML.

雪花飘飘的天空 2024-12-19 18:05:43

当然可以。

- (void)emailExport:(NSString *)filePath
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    // Set the subject of email
    [picker setSubject:@"My desired subject"];

    // Add email addresses
    // Notice three sections: "to" "cc" and "bcc"   

    NSString *valueForEmail = @"[email protected]";
    NSString *valueForCCEmail = @"myCcEmail";
    if( valueForEmail == nil ||  [valueForEmail isEqualToString:@""])
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please set an email address before sending a time entry!" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];        

        return;
    }
    else {
        [picker setToRecipients:[NSArray arrayWithObjects:valueForEmail, nil]];
    }

    if(valueForCCEmail != nil || ![valueForCCEmail isEqualToString:@""])
    {
        [picker setCcRecipients:[NSArray arrayWithObjects:valueForCCEmail, nil]];
    }

    // Fill out the email body text
    NSString *emailBody = @"My email body text.";

    // This is not an HTML formatted email
    [picker setMessageBody:emailBody isHTML:NO];

    // Show email view  
    [self presentModalViewController:picker animated:YES];

    // Release picker
    [picker release];
}

Sure you can.

- (void)emailExport:(NSString *)filePath
{
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc] init];
    picker.mailComposeDelegate = self;

    // Set the subject of email
    [picker setSubject:@"My desired subject"];

    // Add email addresses
    // Notice three sections: "to" "cc" and "bcc"   

    NSString *valueForEmail = @"[email protected]";
    NSString *valueForCCEmail = @"myCcEmail";
    if( valueForEmail == nil ||  [valueForEmail isEqualToString:@""])
    {
        UIAlertView *alert=[[UIAlertView alloc] initWithTitle:@"Please set an email address before sending a time entry!" message:nil delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];        

        return;
    }
    else {
        [picker setToRecipients:[NSArray arrayWithObjects:valueForEmail, nil]];
    }

    if(valueForCCEmail != nil || ![valueForCCEmail isEqualToString:@""])
    {
        [picker setCcRecipients:[NSArray arrayWithObjects:valueForCCEmail, nil]];
    }

    // Fill out the email body text
    NSString *emailBody = @"My email body text.";

    // This is not an HTML formatted email
    [picker setMessageBody:emailBody isHTML:NO];

    // Show email view  
    [self presentModalViewController:picker animated:YES];

    // Release picker
    [picker release];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文