无法从 iPhone 应用程序发送邮件

发布于 2025-01-02 19:55:44 字数 1192 浏览 0 评论 0原文

@interface ViewController : UIViewController { //....yor variables }

在 ViewController.m 文件中:

(void)viewDidLoad {

[super viewDidLoad];

self.title = @"Sample Email Application"; // title of navigation bar

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(composeMail:)] autorelease]; // for adding a compose button //in navigation bar. //...your code }

-(void) composeMail: (id) sender{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
    picker.mailComposeDelegate = self;
    [[picker navigationBar] setTintColor:[UIColor blackColor]];
    [picker setSubject:@"Sample Email Application"];
    [picker setMessageBody:[NSString stringWithFormat:@"Visit for more help %@. ",@"http://google.com"] isHTML:YES];
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
[controller dismissModalViewControllerAnimated:YES]; 
}
@interface ViewController : UIViewController { //....yor variables }

in ViewController.m file:

(void)viewDidLoad {

[super viewDidLoad];

self.title = @"Sample Email Application"; // title of navigation bar

self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCompose target:self action:@selector(composeMail:)] autorelease]; // for adding a compose button //in navigation bar. //...your code }

-(void) composeMail: (id) sender{ 
    MFMailComposeViewController *picker = [[MFMailComposeViewController alloc]init];
    picker.mailComposeDelegate = self;
    [[picker navigationBar] setTintColor:[UIColor blackColor]];
    [picker setSubject:@"Sample Email Application"];
    [picker setMessageBody:[NSString stringWithFormat:@"Visit for more help %@. ",@"http://google.com"] isHTML:YES];
    [self presentModalViewController:picker animated:YES];
    [picker release];
}

-(void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error { 
[controller dismissModalViewControllerAnimated:YES]; 
}

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

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

发布评论

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

评论(1

不念旧人 2025-01-09 19:55:44

您似乎缺少 -setToRecipients,除非您有要发送的地址,否则您无法发送邮件。

[picker setToRecipients:[NSArray arrayWithObjects:@"[email protected]", nil]];

It looks like you are missing the -setToRecipients, which you can't send mail unless you have an address to send to.

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