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)?
Asked
Active
Viewed 2,310 times
4
-
1Yup, its like default mail configuration for your app. Overhere you have to setup SMTP client parameters in code. Find the same in @Karan's answer. – Mrunal Dec 31 '14 at 07:14
2 Answers
2
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

K.D
- 516
- 3
- 14
-
thanks a lot, but "make use of SMTP services on your server side", what does it mean? which server? – Dec 31 '14 at 07:07
-
You have to manage send mail from server side, because apple reject app which make use of sending mail using SMTP in App. – K.D Jan 02 '15 at 06:58
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!!!

Kanan Vora
- 224
- 1
- 9