2012-01-05 156 views
1

我已使用MFMailComposeViewController在我的代碼中發送電子郵件。我也使用可達性代碼來檢查互聯網連接。互聯網連接工作正常。每當我用我的代碼發送郵件時,我都會收到郵件已發送的消息。但我沒有收到任何郵件。沒有從應用發送的電子郵件。我不知道這背後的原因。如果有人知道如何擺脫這個問題,請爲我提供一些解決方案。電子郵件功能無法正常工作

-(void)sendemail 
{ 
    emailBody = @""; 
    mail = [[MFMailComposeViewController alloc] init]; 
    mail.mailComposeDelegate = self; 
    [mail setSubject:@"Report"]; 
    NSURL *url = [NSURL URLWithString:imagePath]; 
    NSData *data = [NSData dataWithContentsOfURL:url]; 
    [mail addAttachmentData:data mimeType:@"image/jpg" fileName:@"licence.png"]; 
    NSMutableString *breakline = [[NSMutableString alloc]init]; 
    [breakline appendString:[NSString stringWithFormat:@"<br>"]]; 
    NSArray *toRecipients = [NSArray arrayWithObject:@"[email protected]"]; 
    [mail setToRecipients:toRecipients]; 
    emailBody = [emailBody stringByAppendingFormat:@"%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@%@",@"Name: ",namestr,breakline,@"Address: ", addresstr,breakline,@"Landmark: ",landmarkstr,breakline,@"City: ", citystr,breakline,@"State: ", statestr,breakline,@"PIN: ", pinstr,breakline,@"Contact No: ",phonestr,breakline,@"Licence:",licencestr,breakline,@"Email Id", emailstr]; 
    [mail setMessageBody:emailBody isHTML:YES]; 
    if (mail != nil) { 
     [self presentModalViewController: mail animated: YES]; 
     [mail release]; 
    } 
} 

謝謝大家。

+0

請檢查是否data''有有效數據。 – Ilanchezhian 2012-01-05 06:45:07

+1

也檢查我們是否可以使用'if([MFMailComposeViewController canSendMail])發送郵件' – Ilanchezhian 2012-01-05 06:47:02

回答

-2

我不知道你的「收件人」數組是否在發送郵件之前被釋放。

當郵件編輯器視圖控制器出現時,您的配方電子郵件是否顯示在「發送到」字段中?

+0

是的,它顯示在收件人選項中。 – Nitin 2012-01-05 06:58:57

0

簡單地嘗試這樣的事:

if([MFMailComposeViewController canSendMail]) 
{ 
MFMailComposeViewController* controller = [[MFMailComposeViewController alloc] init]; 
[controller setToRecipients:[NSArray arrayWithObject:@"[email protected]"]]; 
    controller.mailComposeDelegate = self; 
[controller setSubject:@""]; 
[controller setMessageBody:@"" isHTML:NO]; 
if (controller) [self presentModalViewController:controller animated:YES]; 
[controller release]; 
} 

,不要忘記添加下面的委託方法,返回到您的應用程序:

- (void)mailComposeController:(MFMailComposeViewController*)controller 
     didFinishWithResult:(MFMailComposeResult)result 
        error:(NSError*)error; 
{ 
if (result == MFMailComposeResultSent) { 
    NSLog(@"It's away!"); 
} 
[self dismissModalViewControllerAnimated:YES]; 
    }