English 中文(简体)
当应用程序关闭时如何从后端发送邮件?
原标题:How To send email from backend when application is closed?

i am making an email application,where user can set his time to send email? I am able to send an email in a background process at the user selected time,but only when the application is on,with the help of UILocalNotification. but i want to send the email when user have closed the appliaction. For example:user have selected time for the mail to be send after 10 min and have closed his app before that.

请你帮我一下

我的代码如下:

- (void)application:(UIApplication *)application didReceiveLocalNotification:(UILocalNotification *)notification
{

    NSLog(@"didReceiveLocalNotification");

    NSLog(@"
Notification dic = %@ %@",notification.userInfo,notification.alertBody);

    dictUser=notification.userInfo;
    [dictUser retain];

    NSLog(@"dictuser124:%@",dictUser);
    [dictUser retain];

    if ([str_info4 isEqualToString:@"0"]) 
    {
        [self sendEMAIL];
    }
    else if ([str_info4 isEqualToString:@"1"]) 
    {
        [self sendSMS];
    }

}

-(void)sendEMAIL
{
    [dictUser retain];

    SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];


    //testMsg.fromEmail = @"Lexi mobile";//[email protected]

    testMsg.fromEmail = str_uname;
    NSLog(@"str_Uname=%@",testMsg.fromEmail);

    str_info = [str_info stringByReplacingOccurrencesOfString:@"," withString:@""];
    testMsg.toEmail = str_info;
    NSLog(@"autoemail=%@",testMsg.toEmail);


    testMsg.relayHost = @"smtp.gmail.com";


    testMsg.requiresAuth = YES;


    testMsg.login = str_uname;
    NSLog(@"autoelogin=%@",testMsg.login);

    testMsg.pass = str_password;
    NSLog(@"autopass=%@",testMsg.pass);

    testMsg.subject = @"Schedule Sms And Email";


    testMsg.wantsSecure = YES; 

    NSString *sendmsg=[[NSString alloc]initWithFormat:@"%@",str_info2];
    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]);

}
最佳回答

据我所知,我知道,当申请被关闭时,这种申请无法执行,而且没有可供使用的申请实例。

我宁愿建议同样使用后端的SERVER系统执行推力通知。 您可以在数据库中节省时间, 用户在数据库中必须发送电子邮件, 并相应写入 CRONS 用于在那个时候发送电子邮件 。

问题回答

据我所知,一旦应用程序关闭,你就不能做任何操作。 您可以在后端的SERVER上进行操作, 以便自动执行操作 。

如果程序已经关闭, 则无法安排从应用程序发送电子邮件。 您的最佳选择是在后端服务器上处理所有这些东西。 应用程序存储器中该发送信件的地址是何时。 设置一个 cronjob, 用于通过需要发送的信件的队列进行民意调查, 如果计划的时间匹配, 则发送电子邮件 。





相关问题
List Contents of Directory in a UITableView

I am trying to list the contents of Ringtones directory in a TableView, however, I am only getting the last file in the directory in ALL cells, instead of file per cell. This is my code: - (...

iPhone NSUserDefaults persistance difficulty

In my app i have a bunch of data i store in the NSUserdefaults. This information consists of an NSObject (Object1) with NSStrings and NSNumbers and also 2 instances of yet another object (Object2). ...

Writing a masked image to disk as a PNG file

Basically I m downloading images off of a webserver and then caching them to the disk, but before I do so I want to mask them. I m using the masking code everyone seems to point at which can be found ...

Resize UIImage with aspect ratio?

I m using this code to resize an image on the iPhone: CGRect screenRect = CGRectMake(0, 0, 320.0, 480.0); UIGraphicsBeginImageContext(screenRect.size); [value drawInRect:screenRect blendMode:...

Allowing interaction with a UIView under another UIView

Is there a simple way of allowing interaction with a button in a UIView that lies under another UIView - where there are no actual objects from the top UIView on top of the button? For instance, ...

热门标签