0

我正在制作一个我想使用 smtp 服务器发送电子邮件的应用程序。

它工作正常,但如果用户没有提供正确的 gmail 帐户详细信息,例如(电子邮件 ID 和密码),则不会发送电子邮件。

我想要做的是我想从 iPhone 的设置选项卡访问用户 gmail 帐户详细信息到我的应用程序中?

是否可以将 gmail 帐户详细信息检索到应用程序中?

这个你能帮我吗。

以下是我的代码:

-(IBAction)sendemail
{
    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
    //testMsg.fromEmail = @"Lexi mobile";//nimit51parekh@gmail.com
    testMsg.fromEmail = soundOn;
    NSLog(@"str_Uname=%@",testMsg.fromEmail);
    //str_info = [str_info stringByReplacingOccurrencesOfString:@"," withString:@""];
    testMsg.toEmail = [string_emailinfo objectAtIndex:0];
    NSLog(@"autoemail=%@",testMsg.toEmail);
    testMsg.relayHost = @"smtp.gmail.com";
    testMsg.requiresAuth = YES;
    testMsg.login = soundOn;
    NSLog(@"autoelogin=%@",testMsg.login);
    testMsg.pass = vibrateOn;
    NSLog(@"autopass=%@",testMsg.pass);
    testMsg.subject = @"Photo Sharing";
    testMsg.wantsSecure = YES; 

    NSURL *url = [[NSURL alloc]initWithString:@"http://itunes.apple.com/us/app/umix-radio/id467041430?mt=8"];
    NSString *msg2 = [NSString stringWithFormat:@"<html><b><a href=\"%@\">DOWNLOAD NOW</a></b>&nbsp&nbsp<a href=\"http://itunes.apple.com/us/app/umix-radio/id467041430?mt=8\"></a></html>",url];
    NSString *sendmsg=[[NSString alloc]initWithFormat:@"%@",msg2];
    NSLog(@"automsg=%@",sendmsg);

    testMsg.delegate = self;

    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/plain",kSKPSMTPPartContentTypeKey,
                                                            sendmsg,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];

    testMsg.parts = [NSArray arrayWithObjects:plainPart,nil];
    [testMsg send];

    // [self DeleteRowAfterSending];
    //[self performSelector:@selector(DeleteRowAfterSending) withObject:nil afterDelay:5.0];
}

-(void)messageSent:(SKPSMTPMessage *)message
{
    [message release];

    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Success" message:@"Your email is sent successfully" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];

    NSLog(@"delegate - message sent");
}

-(void)messageFailed:(SKPSMTPMessage *)message error:(NSError *)error
{
    [message release];

    // open an alert with just an OK button
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Fail" message:@"Message sending failure" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];

    NSLog(@"delegate - error(%d): %@", [error code], [error localizedDescription]);
}
4

2 回答 2

1

我想要做的是我想从 iPhone 的设置选项卡访问用户 gamil 帐户详细信息到我的应用程序中?是否可以将 gamil 帐户详细信息检索到应用程序中?

不,并且有充分的理由:该功能将允许任何开发人员访问任何人的电子邮件帐户

那将是一个巨大的安全漏洞。

就像位置服务一样,您只需要要求用户输入他们的电子邮件地址和密码。并希望他们希望使用此类个人信息来信任您的应用程序。(假设 Apple 完全批准了您的应用程序。)

于 2012-06-01T07:10:48.623 回答
1

让用户从 Google 向您的应用授权。在他们的开发者网站上使用 google api 检查 oauth 授权? https://developers.google.com/accounts/docs/OAuth2

像往常一样,用户通过 google api 使用他的帐户登录并返回给你一个 access_token 以从他的帐户中获取信息,包括你需要的他的电子邮件。

于 2012-06-01T07:50:10.700 回答