通过iOS应用程序从虚拟地址自动发送电子邮件

时间:2014-12-24 04:34:26

标签: ios email parse-platform

我们说我添加了在我的应用中报告内容的功能。在用户报告该内容后,我希望从虚拟电子邮件地址(而不是用户的电子邮件地址)向我发送一封电子邮件,其中包含有关该事件报告原因的详细信息。反正有没有这样做?想想" mailTo" PHP中的函数。这真的很有用。如果有帮助,我正在使用parse.com。重申一下,我想自动从应用程序中将DUMMY电子邮件发送到我的电子邮箱。所以没有MFMailComposeViewController。

3 个答案:

答案 0 :(得分:0)

您只需要设置一个可以发送电子邮件的服务器,并在您想要发送电子邮件时从应用程序向服务器发出请求。这可以通过多种方式实现,因为有许多API可以这样做。其中一个特别符合您兴趣的API可能是SendGrid

答案 1 :(得分:0)

是的,您可以使用云代码和mandrill帐户实现此目的。看看这个post

我有这样的设置:

template.js

Parse.Cloud.define("sendTemplate", function(request, response) {
var Mandrill = require('cloud/mandrillTemplateSend.js');
Mandrill.initialize('SOMEKEY');
Mandrill.sendTemplate({
    template_name: "template name",
    template_content: [{
        name: "TEMPLATE CONTENT NAME",
        content: request.params.content
    }],
    message: {
        to: [{
            email: "EMAIL@EMAIL.COM",
            name: "NAME"
        }],
        important: true
    },
    async: false
}, {
    success: function (httpResponse) {
        console.log(httpResponse);
        response.success("Email sent!");
    },
    error: function (httpResponse) {
        console.error(httpResponse);
        response.error("Uh oh, something went wrong");
    }
});
});

mandrillTemplateSend.js

var _apiUrl = 'mandrillapp.com/api/1.0';
var _apiKey = 'API KEY';

exports.initialize = function(apiKey) {
    _apiKey = apiKey;
};

exports.sendTemplate = function(request, response) {
    request.key = _apiKey;

    return Parse.Cloud.httpRequest({
        method: 'POST',
        headers: {
            'Content-Type': 'application/json'
        },
        url: 'https://' + _apiUrl + '/messages/send-template.json',
        body: request,
        success: function(httpResponse) {
            response.success(httpResponse);
        },
        error: function(httpResponse) {
            response.error(httpResponse);
        }
    });
};

您可以在云中创建一个功能,并在必要时从您的应用中调用它。要了解调用云功能,您可以访问解析文档here

希望这会有所帮助!!

答案 2 :(得分:0)

您可以使用此代码直接从您的代码发送电子邮件:

-(void)sendEmail
{
    NSString *htmlString = [self createAttachment];
    NSDictionary *plainPart = [NSDictionary dictionaryWithObjectsAndKeys:@"text/html",kSKPSMTPPartContentTypeKey,
                               htmlString,kSKPSMTPPartMessageKey,@"8bit",kSKPSMTPPartContentTransferEncodingKey,nil];


NSArray *pathsImage = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docspath = [pathsImage objectAtIndex:0];
pathsImage = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);

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 = @"Mersen Information(Final Email)";
testMsg.delegate = self;

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    [testMsg send];
});

}

试试吧,

一切顺利!!!