Xcode 4 / iOS - 使用SMTP从我的应用程序发送电子邮件 [英] Xcode 4 / iOS - Send an email using SMTP from inside my app

查看:525
本文介绍了Xcode 4 / iOS - 使用SMTP从我的应用程序发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一个框架,只需让我从我的应用程序内发送一封电子邮件。我已经尝试过MailCore,Pantomime和SKPSMTP,没有运气。我不能让他们在Xcode中编译,所以我推测他们已经过时了。有什么办法可以做到吗?如果是这样,怎么办?谢谢。

I've been looking around for a framework to simply allow me to send an email from inside my app. I have tried MailCore, Pantomime and SKPSMTP all with no luck. I can't get them to compile in Xcode, so I presumed they were outdated. Is there any way I can do this? If so, how? Thanks.

推荐答案

您可以轻松地从iOS设备发送电子邮件。不需要实现SMTP和所有。在iOS中使用内置电子邮件功能的最佳方法是让您访问通讯录!所以它自动完成名称,电子邮件地址。 Yaaiiii !!

You can easily send emails from your iOS device. No need to implement SMTP and all. Best thing about using inbuilt emailing facilities in iOS is it gives you access to the address book! So it auto-completes names, email addresses. Yaaiiii!!

Include, AddressBook AddressBookUI MessageUI 框架和代码这样。请注意,您甚至可以选择将内容作为HTML发送!

Include, AddressBook,AddressBookUI and MessageUI frameworks and code something like this. Note you can even choose to send content as HTML too!

#import <MessageUI/MessageUI.h>
#import <AddressBook/AddressBook.h>
#import <AddressBookUI/AddressBookUI.h>

MFMailComposeViewController *mailComposer; 
mailComposer  = [[MFMailComposeViewController alloc] init];
mailComposer.mailComposeDelegate = self;
[mailComposer setModalPresentationStyle:UIModalPresentationFormSheet];
[mailComposer setSubject:@"your custom subject"];
[mailComposer setMessageBody:@"your custom body content" isHTML:NO];
[self presentModalViewController:mailComposer animated:YES];
[mailComposer release];

为了完整起见,如果用户按下,我必须写这个选择器来关闭电子邮件窗口取消发送 -

For the sake of completeness, I have to write this selector to dismiss the email window if the user presses cancel or send -

- (void)mailComposeController:(MFMailComposeViewController*)controller 
          didFinishWithResult:(MFMailComposeResult)result
                        error:(NSError*)error 
{ 
    if(error) NSLog(@"ERROR - mailComposeController: %@", [error localizedDescription]);
    [self dismissModalViewControllerAnimated:YES];
    return;
}

快乐编码...

这篇关于Xcode 4 / iOS - 使用SMTP从我的应用程序发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆