如何发送电子邮件给receipent在背景的iOS5? [英] How to send an email to a receipent in background in iOS5?

查看:244
本文介绍了如何发送电子邮件给receipent在背景的iOS5?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个iPhone应用程序,我想发送电子邮件到谁忘记了他们的通行证code的人。我要发送邮件在后台(不能使用MFMailComposeViewController本),并应用程序不能推到背景。有没有办法实现这一目标?

In an iPhone app,I want to send an email to a person who has forgotten about their passcode . I want to send the mail in background (cant use MFMailComposeViewController for this) and also the app must not be pushed to background . Is there a way to achieve this?

推荐答案

这样做的最好方法是使用SKPSMTPMessage。你可以从这里下载: https://github.com/jetseven/skpsmtpmessage 这是我用了一个很简单的解决办法使用前,忘记密码在iOS应用的解决方案。要实现只需将下载的文件拖放到你的应用程序中,#进口的的SKPSMTPMessage.h到你的类,并实现以下code:

The best way of doing this is using SKPSMTPMessage. You can download it from here: https://github.com/jetseven/skpsmtpmessage This is a very easy solution that I have used before for using "Forgot Password" solutions in iOS apps. To implement simply drag the downloaded files into your application, #import the the "SKPSMTPMessage.h" into your class, and implement the following code:

.H

#import "SKPSMTPMessage.h"

@interface SomeView : UIViewController <SKPSMTPMessageDelegate> {

}

- (IBAction)forgotPassword;

.M

- (IBAction)forgotPassword {
SKPSMTPMessage *forgotPassword = [[SKPSMTPMessage alloc] init];
[forgotPassword setFromEmail:@"some-email@gmail.com"];  // Change to your email address
[forgotPassword setToEmail:@"user-email@gmail.com"]; // Load this, or have user enter this
[forgotPassword setRelayHost:@"smtp.gmail.com"];
[theMessage setRequiresAuth:YES]; // GMail requires this
[forgotPassword setLogin:@"some-email@gmail.com"]; // Same as the "setFromEmail:" email
[forgotPassword setPass:@"password"]; // Password for the Gmail account that you are sending from
[forgotPassword setSubject:@"Forgot Password: My App"]; // Change this to change the subject of the email
[forgotPassword setWantsSecure:YES]; // Gmail Requires this
[forgotPassword setDelegate:self]; // Required

NSString *newpassword = @"helloworld";

NSString *message = [NSString stringWithFormat:@"Your password has been successfully reset. Your new password: %@", newpassword];
NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain", kSKPSMTPPartContentTypeKey, message, kSKPSMTPPartMessageKey, @"8bit" , kSKPSMTPPartContentTransferEncodingKey, nil];

[forgotPassword setParts:[NSArray arrayWithObjects:plainPart, nil]];
[forgotPassword send];
}

另外,一定要包括在.M下面的方法。您可以根据要显示给用户什么改变UIAlertViews的内容。

Also be sure to include the following methods in the .m. You can change the contents of the UIAlertViews depending on what you want to display to the user.

- (void)messageSent:(SKPSMTPMessage *)message {
    NSLog(@"Message Sent");

    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Password Reset" message:@"Check your email for your new password." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}

- (void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error {
    NSLog(@"Message Failed With Error(s): %@", [error description]);
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"There was an error reseting your password. Please try again later." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
    [alert show];
}

您还需要执行以下操作前,这将工作。
你的目标 - >获取信息 - >构建 - >所有配置 - >其他链路标志:-ObjC
如果您需要这方面的帮助,请参阅http://developer.apple.com/qa/qa2006/qa1490.html

You also need to do the following before this will work. Your Target -> Get Info -> Build -> All Configurations -> Other Link Flags: "-ObjC" If you need help with this, see http://developer.apple.com/qa/qa2006/qa1490.html

编辑:
* CFNetwork.framework也必须添加这个工作! *

让我知道如果你有任何问题。

Let me know if you have any more questions.

谢谢,
雅各

这篇关于如何发送电子邮件给receipent在背景的iOS5?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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