使用emailyak在angularjs函数中发送电子邮件

Sending a email in a angularjs function with emailyak

本文关键字:电子邮件 函数 emailyak angularjs 使用      更新时间:2023-09-26

我想用javascript函数发送一封电子邮件。我为此创建了一个emailyak帐户,可以使用curl命令发送电子邮件。

像这样:

curl -H "Content-Type: application/json" -d '{"FromAddress" : "info@mydomain.simpleyak.com","FromName" : "My App","ToAddress": "blabal@gmail.com","Subject" : "Test","TextBody" : "Hello"}' https://api.emailyak.com/v1/my_api_key/json/send/email/

但是,如果我从javascript端进行等效的调用,它就不起作用。

我使用:

.controller('AppointmentCtrl', function($scope, Services) {
    $scope.sendMail = function() {
        var req = {
            method: 'POST',
            url: 'https://api.emailyak.com/v1/my_api_key/json/send/email/',
            headers: {
                'Content-Type': 'application/json; charset=utf-8'
            },
            data: {
                "FromAddress" : "info@mysubdomain.simpleyak.com",
                "FromName" : "My App",
                "ToAddress": "blabla@gmail.com",
                "Subject" : "Subject",
                "TextBody" : "Body"
            }
        };
        $http(req).
            success(function(data, status, headers, config) {
                // this callback will be called asynchronously
                // when the response is available
                alert("Success");
                //return data;
            }).
            error(function(data, status, headers, config) {
                // called asynchronously if an error occurs
                // or server returns response with an error status.
                alert("Error:"+JSON.stringify(status));
                //return false;
            });
    }
});

在我的html中,我使用:

<button ng-click="sendMail()" class="button button-positive button-block">
    Absenden
</button>

这是一个离子框架应用程序,我在iOS模拟器中运行测试。我检查了模拟器的互联网连接,它正常工作。如果emailyak有一些问题,那么终端的电话就无法工作。

这里有什么问题?

在查看示例代码时,首先想到的是$http模块没有传递到控制器函数中。

我认为这一行:

.controller('AppointmentCtrl', function($scope, Services) {

应为:

.controller('AppointmentCtrl', function($scope, $http, Services) {