iOS - Send an email automatically (NOT from user's account)

懵懂的女人 提交于 2019-12-04 09:58:45

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

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!!!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!