How can I send an email automatically from an app, to myself, NOT from the user's account(that is not possible without user interaction), but from another email id of mine(with username and password given in the code)?
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Yes, you can send email without user interation. But you have to make use of SMTP services on your server side.
Pls Refere: http://iosameer.blogspot.in/2013/01/sending-e-mail-in-background-from-ios_25.html
回答2:
You need to import:
#import "SKPSMTPMessage.h"
And then use this funtion:
-(void)sendEmail
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
// SKPSMTPMessage *testMsg = [[SKPSMTPMessage alloc] init];
testMsg = [[SKPSMTPMessage alloc] init];
testMsg.fromEmail = [defaults objectForKey:@"fromEmail"];
testMsg.toEmail = [defaults objectForKey:@"toEmail"];
testMsg.bccEmail = [defaults objectForKey:@"bccEmal"];
testMsg.relayHost = [defaults objectForKey:@"relayHost"];
testMsg.requiresAuth = [[defaults objectForKey:@"requiresAuth"] boolValue];
if (testMsg.requiresAuth) {
testMsg.login = [defaults objectForKey:@"login"];
testMsg.pass = [defaults objectForKey:@"pass"];
}
testMsg.wantsSecure = [[defaults objectForKey:@"wantsSecure"] boolValue]; //
testMsg.subject = @"Your Email subject";
testMsg.delegate = self;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
[testMsg send];
});
}
And then call this function from where you need to send the Email:
[self sendEmail];
Try it, it is working... All the best!!!