2012-09-27 56 views
16

我使用Parse.com(JavaScript SDK),我希望用户能够从我的应用程序发送电子邮件。基本上,他们使用应用程序创建一个页面,然后我需要允许他们输入一个电子邮件地址列表;该应用程序会发送每个地址链接到他们创建的页面。我的Parse.com应用程序如何发送电子邮件?

虽然我可以在文档中找到任何告诉我如何发送电子邮件的内容。我可以把电子邮件地址列表和生成电子邮件,我只是不知道如何发送它。

这是可能与解析,如果是这样,任何人都可以指向我的方向正确吗?

谢谢!

回答

4

没有本地方法来做到这一点。你最好的选择是等到Parse's Cloud Code支持第三方HTTP请求。我做的,你怎么能做到这一点使用铁工+红宝石发送电子邮件快速的样机,但你当然可以使用其他语言:通过一些云

http://news.ycombinator.com/item?id=4506888

+7

我的回答停止投票。下面的应该是被接受的答案。 – user94154

30

解析云代码模块现支持发送电子邮件邮件服务提供商:

+0

哪一个是最好的? :) –

+0

@ M.Y。 mandrill .. – SuperUberDuper

+0

但解析有它自己的库发送电子邮件。他们在验证电子邮件“打开”时发送电子邮件的方式。没有任何方法可以访问它? – lxknvlk

5

这里是@ uudaddy的回答

public void sendMail(View view) { 
    Map<String, String> params = new HashMap<>(); 
    params.put("text", "Sample mail body"); 
    params.put("subject", "Test Parse Push"); 
    params.put("fromEmail", "[email protected]"); 
    params.put("fromName", "Source User"); 
    params.put("toEmail", "[email protected]"); 
    params.put("toName", "Target user"); 
    ParseCloud.callFunctionInBackground("sendMail", params, new FunctionCallback<Object>() { 
     @Override 
     public void done(Object response, ParseException exc) { 
      Log.e("cloud code example", "response: " + response); 
     } 
    }); 
} 

服务器端JS代码的Android版本(main.js )解析云

Parse.Cloud.define("sendMail", function(request, response) { 
var Mandrill = require('mandrill'); 
Mandrill.initialize('12AkxxxxxxxxxxxxxxrZEg'); 

Mandrill.sendEmail({ 
message: { 
text: request.params.text, 
subject: request.params.subject, 
from_email: request.params.fromEmail, 
from_name: request.params.fromName, 
to: [ 
{ 
email: request.params.toEmail, 
name: request.params.toName 
} 
] 
}, 
async: true 
},{ 
success: function(httpResponse) { 
console.log(httpResponse); 
response.success("Email sent!"); 
}, 
error: function(httpResponse) { 
console.error(httpResponse); 
response.error("Uh oh, something went wrong"); 
} 
}); 
}); 
+0

我得到的答复为空 –

+0

您应该按照@ uudaddy的回答来设置服务器休息,并且从那里开始下降。 – sector11

+0

更新我的代码请检查。 – sector11

5

有人可能会发现使用Mailgun,iOS和Parse Cloud的有用示例。

因为Mandril目前只有4k免费邮件,所以我决定和Mailgun一起去。

请注意,您必须有权访问您的域名才能设置“TXT”和“CNAME”记录,证明Mailgun您是域名的所有者。

云代码:

// Use Parse.Cloud.define to define as many cloud functions as you want. 
// For example: 
Parse.Cloud.define("hello", function(request, response) { 
    response.success("Hello world!"); 
}); 

Parse.Cloud.define("mailSend", function(request, response) { 

    var Mailgun = require('mailgun'); 
    Mailgun.initialize('DOMAIN_NAME', 'API_KEY'); 

    Mailgun.sendEmail({ 
     to: request.params.target, 
     from: request.params.originator, 
     subject: request.params.subject, 
     text: request.params.text 
    }, { 
     success: function(httpResponse) { 
     console.log(httpResponse); 
     response.success("Email sent!"); 
     }, 
     error: function(httpResponse) { 
     console.error(httpResponse); 
     response.error("Uh oh, something went wrong"); 
     } 
    }); 

}); 
在ObjC项目

现在的地方:

[PFCloud callFunctionInBackground:@"mailSend" 
        withParameters:@{ 
            @"target": @"[email protected]", 
            @"originator": @"[email protected]", 
            @"subject": @"Hey There", 
            @"text": @"This is your iOS originated mail" 
            } 
          block:^(NSString *result, NSError *error){ 

           NSLog(@"error %@", error); 
           NSLog(@"result %@", result); 

          }]; 
+0

如何添加TXT和CNAME记录?和哪里? –

+0

您可以将它们添加到托管服务提供商管理面板中。未经购买/获得托管,您不能使用此功能。 –

相关问题