简体   繁体   English

使用Parse.com通过iOS应用创建新用户时发送电子邮件

[英]Send email when a new user is created via iOS app using Parse.com

I want to send an email each time a new user is created in my iOS app. 每当我在iOS应用中创建新用户时,我都想发送电子邮件。 I'm using Parse.com as my back-end and have been reading about Cloud Code. 我将Parse.com用作后端,并一直在阅读有关Cloud Code的信息。 I'm assuming I can use this to monitor object creation and kick off a function to send an email when a specific object (user) is created in the database. 我假设我可以使用它来监视对象的创建,并启动在数据库中创建特定对象(用户)时发送电子邮件的功能。 I know I can create a function within CloudCode then call this function in my iOS app once a user is created, but I'd like to be able to do this same thing without submitting an update to the App Store. 我知道我可以在CloudCode中创建一个函数,然后在创建用户后在我的iOS应用中调用此函数,但是我希望能够做同样的事情而无需向App Store提交更新。 Is there a way to accomplish this without submitting a new binary? 有没有一种方法可以在不提交新二进制文件的情况下完成此任务?

You can add an afterSave Cloud Code function then you don't need to change your app - the new code will simply be invoked every time your user object is saved. 您可以添加afterSave Cloud Code函数,然后无需更改应用程序-每次保存用户对象时,新代码便会被调用。 This example uses SendGrid, so you would need a SendGrid account 本示例使用SendGrid,因此您需要一个SendGrid帐户

Parse.Cloud.afterSave(Parse.User, function(request) {

    if(!(request.object.existed())){
       var SendGrid = require("sendgrid");  
       SendGrid.initialize("username", "password");

       SendGrid.sendEmail({
          to: "email@example.com",
          from: "SendGrid@CloudCode.com",
          subject: "Hello from Cloud Code!",
          text: "Using Parse and SendGrid is great!"
        }, {
          success: function(httpResponse) {
             console.log(httpResponse);
          },
          error: function(httpResponse) {
             console.error(httpResponse);
          }
      });
    }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM