After creating an emailyak account, I attempted to send an email using a JavaScript function. While I was able to successfully send an email with a curl command, I encountered difficulties when trying to replicate the same function in JavaScript.
Here is the curl command I used:
curl -H "Content-Type: application/json" -d '{"FromAddress" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9ef7f0f8f1def3e7faf1f3fff7f0b0edf7f3eef2fbe7fff5b0fdf1f3">[email protected]</a>","FromName" : "My App","ToAddress": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="9efcf2fffcfff2def9f3fff7f2b0fdf1f3">[email protected]</a>","Subject" : "Test","TextBody" : "Hello"}' https://api.emailyak.com/v1/my_api_key/json/send/email/
However, my JavaScript equivalent did not work. The code snippet I used in my Angular controller is:
.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" : "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="244d4a424b64495d575146404b49454d4a0a574d495448415d454f0a474b49">[email protected]</a>",
"FromName" : "My App",
"ToAddress": "<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="04666865666865446369656d682a676b69">[email protected]</a>",
"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;
});
}
});
In my HTML, I implemented the button as follows:
<button ng-click="sendMail()" class="button button-positive button-block">
Send
</button>
This issue occurred in an Ionic framework application while testing in the iOS Simulator. The simulator has a working internet connection and emailyak appears to be functioning correctly when tested in the terminal. What could be the cause of this problem?