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

不想你离开。 提交于 2019-12-21 18:13:23

问题


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



来源:https://stackoverflow.com/questions/27717468/ios-send-an-email-automatically-not-from-users-account

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