我正在制作一个我想使用 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>  <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]);
}