I have a code defined as
Parse.Cloud.define("mailgunSendMail", function(request, response) {
var Mailgun = require('mailgun');
Mailgun.initialize('photoshare.com', 'APPKey');
Mailgun.sendEmail({
to: "toTestUser#mail.com",
from: "fromTestUser#mail.com",
subject: "Hello from Cloud Code!",
text: "Using Parse and Mailgun is great!",
attachment:"ZXhhbXBsZSBmaWxl"
}, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
Mail was sent successfully and recipient got the mail but the attachment is missing. How can i send attachment in the form of data?
According to parse, at this point there is no way to send attachments in an email. Check this link
However, if you can include your image file in your HTML code like this if this serves your needs.
html: '<html><body style="text-align:center;"><img border="0" src="http://files.parse.com/6ffa6b80-d0eb-401f-b663-22d4a16df004/bfed9ac4-058c-41fc-a0f1-fb6155572c12-ad77a082-453f-42f7-94ef-40c3f3e885e6.png" alt="Pulpit rock" width="300" height="150"></body></html>'
Subash answer is right. I just edited to my question:
Parse.Cloud.define("mailgunSendMail", function(request, response) {
var Mailgun = require('mailgun');
Mailgun.initialize('photoshare.com', 'AppKey');
Mailgun.sendEmail({
to: "toTestuser#mail.com",
from: "fromTestUser#mail.com",
subject: "Hello from Cloud Code!",
text: "Using Parse and Mailgun is great!",
html: '<html><body><img src="' + request.params.imageUrlKey + '"></body></html>' }, {
success: function(httpResponse) {
console.log(httpResponse);
response.success("Email sent!");
},
error: function(httpResponse) {
console.error(httpResponse);
response.error("Uh oh, something went wrong");
}
});
});
Where imageUrlKey is a parameter key which contains image url.
Related
I have an Office 365 extension that provides its own "Send" button which does some custom processing of the "draft" email and sends it through other means (ie not Office 365 Web). Since the email isn't sent by Outlook it never makes it to the sent folder (which makes sense). I would like to take that draft email and move it to the sent folder and remove the draft flag so it looks like it was sent by Outlook 365 Web.
var getMessageUrl = Office.context.mailbox.restUrl + '/v2.0/me/messages/' + itemId;
var data = JSON.stringify({ 'ToRecipients': [{ 'EmailAddress': { 'Address': 'sheprts#cox.net', 'Name': 'Katie Jordan' } }], 'IsRead': true, 'IsDraft': false });
$.ajax({
url: getMessageUrl,
type: 'PATCH',
dataType: 'json',
headers: { 'Authorization': 'Bearer ' + accessToken, 'Content-Type': 'application/json' },
data: data
})
})
.done(function (item) {
})
.fail(function (error) {
var err = ""
});
The request above works fine except the changing of the draft flag. If this isn't the solution what else can I do? I need to get a draft email into the sent folder as "Not" a draft.
Unfortunately you cannot create non-draft messages using the API.
Change your "other means" and set the "SaveInSentFolder" flag; or change to SMTP for your "other means".
I'm trying to send e-mails with MS Graph 1.0 and I have not any get any result or response. E-Mails haven't been sent and sendMail method don't return any error o message... it only says "null".
My code is based on this example https://github.com/microsoftgraph/msgraph-sdk-javascript#post-and-patch and looks like this:
// Initialize Graph client
const client = graph.Client.init({
authProvider: (done) => {
done(null, accessToken);
}
});
try {
// construct the email object
var mail = {
subject: "Microsoft Graph JavaScript Sample",
toRecipients: [{
emailAddress: {
address: "mail#domain.com"
}
}],
body: {
content: "<h1>MicrosoftGraph JavaScript Sample</h1>Check out https://github.com/microsoftgraph/msgraph-sdk-javascript",
contentType: "html"
}
};
client
.api('/me/sendMail')
.post({message: mail}, (err, res) => {
console.log("---> " + res);
});
console.log("Try ends");
} catch (err) {
parms.message = 'Error retrieving messages';
parms.error = { status: `${err.code}: ${err.message}` };
parms.debug = JSON.stringify(err.body, null, 2);
res.render('error', parms);
}
I guess mail var needs a header, but anyway, API should return me something, right? And, obviously, which is the problem with the email sending?
I finally added rawResponse to .post call and look at err log...
client
.api('/me/sendMail')
.header("Content-type", "application/json")
.post({message: mail}, (err, res, rawResponse) => {
console.log(rawResponse);
console.log(err);
});
... and I could see that I had problem with my authentication token. So, I was using the api correctly and code from the question is ok.
So we are using Firebase to send notifications to our users on our iOS app. It works great in the console, but now we are looking to allow a few more people to send notifications, and we don't really want them signing into Firebase to do that. One solution we came up with is to put a form on our website and let them sign in and send notifications from there, but we can't get it to work. The code below is a stripped down version of what we have right now. It uses the cloud messaging API to send an HTTP POST request to a specific topic and Firebase responds with a message_id, however no message is delivered on any of the devices.
<!DOCTYPE html>
<html>
<body>
<input id="title"></input>
<input id="message"></input>
<button>Submit</button>
</body>
<script src="https://code.jquery.com/jquery-1.12.2.min.js" integrity="sha256-lZFHibXzMHo3GGeehn1hudTAP3Sc0uKXBXAzHX1sjtk=" crossorigin="anonymous"></script>
<script>
$("button").click(function () {
var title = $("#title").val();
var message = $("#message").val();
var param = {
"to" : "/topics/myTopic",
"content_available" : true,
"notification" : {
"title" : title,
"body" : message
}
};
$.ajax({
url: 'https://fcm.googleapis.com/fcm/send',
type: "POST",
headers: { 'Authorization': 'key=<myKey>', 'Content-Type': 'application/json' },
data: JSON.stringify(param),
success: function () {
alert("success");
},
error: function(error) {
alert("error: "+error);
}
});
});
</script>
</html>
Solution:
After we played around with it a bit more, we found that content_available should really be false in order to actually display a notification in our app. We also made sure to implement jQuery variables correctly. You can see our improved script for handling everything below.
$("button").click(function () {
// Grab the input values
$title = $("#title").val();
$message = $("#message").val();
// Verify that the message is not left empty
if ( $message.length < 2 ){
// Message is empty
return;
}
// Create the JSON object
var paramaters = {
"to" : "/topics/test",
"content_available" : false,
"notification" : {
"title" : $title,
"body" : $message
}
};
// Send request
$.ajax({
url: 'https://fcm.googleapis.com/fcm/send',
type: "POST",
headers: { 'Authorization': 'key=$key', 'Content-Type': 'application/json' },
data: JSON.stringify(paramaters),
success: function (e) {
// Process succeeded
console.log(e);
},
error: function(error) {
// Display error message
}
});
});
We also made sure that our server keys were not included directly in our code as Frank mentioned in his comment. Everything now works and we are successfully receiving notifications.
Is there any possibility to call "WSDL" method in cloud code ?
for example, there is a "WSDL" web service and i want to check if there is an new data in it and if there is i want to send push notification to user. I got the logic, but i could not find any information about "WSDL" in parse.com documentation.
this didn't help:
Parse.Cloud.httpRequest({
url: 'https://services.rs.ge/WayBillService/WayBillService.asmx',
params: {
su : 'test1'
},
success: function(httpResponse) {
console.log(httpResponse.text);
},
error: function(httpResponse) {
console.error('Request failed with response code ' + httpResponse.status);
}
});
Sure you can, now, first we need to get a few things straight.
WSDL is just the definition of the services "Web Services Description Language"
You are talking SOAP here "Simple Object Access Protocol"
If you go to https://services.rs.ge/WayBillService/WayBillService.asmx in your browser, you will se a list of methods/SOAPActions that are available to you and if you click them, you will see an example of how to call the method.
For example, get_server_time, https://services.rs.ge/WayBillService/WayBillService.asmx?op=get_server_time
Example how to call get_server_time:
Parse.Cloud.job('soap', function(request, status) {
var Buffer = require('buffer').Buffer,
buffer = new Buffer(
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap12:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://www.w3.org/2003/05/soap-envelope">' +
' <soap12:Body>' +
' <get_server_time xmlns="http://tempuri.org/" />' +
' </soap12:Body>' +
'</soap12:Envelope>'
);
Parse.Cloud.httpRequest({
method: 'POST',
url: 'https://services.rs.ge/WayBillService/WayBillService.asmx',
headers: {
'Content-Type': 'text/xml; charset=utf-8'
},
body: buffer,
success: function(httpResponse) {
status.success(httpResponse.text);
},
error: function(httpResponse) {
status.error('Request failed with response code ' + httpResponse.status);
}
});
});
After Oauth authentification done with Oauth.io, i can't have access to the user_timeline, it only show a bad authentification data with the code 215. Maybe i forgot some parameters or my connexion is wrong ? I did'nt find any issue to my problem. I think i'm missing something but i can't find what.
I paste my code below, if someone could help me :)
Thanks
$(document).on( 'deviceready', function() {
OAuth.initialize("my key");
$('#twitter-connect').on('click', function() {
OAuth.popup('twitter', function(error, result) {
result.get('/1.1/account/verify_credentials.json').done(function(data) {
console.log(data);
var screen_name = data.screen_name;
$.ajax({
url : "https://api.twitter.com/1.1/statuses/user_timeline.json",
dataType: "json",
type: "get",
data:{
screen_name: screen_name
},
error: function(xhr, status){
alert(xhr.responseText);
},
success: function(data, xhr, status){
console.log(data);
}
});
});
});
});
});
You have used jQuery.ajax instead of the result of OAuth.popup() to make the API call. Take a look at this jsFiddle: http://jsfiddle.net/LCZu3/1/
You can do it this way:
$(document).on( 'deviceready', function() {
OAuth.initialize("my key")
$('#twitter-connect').on('click', function() {
OAuth.popup('twitter', function(error, result) {
result.get('/1.1/account/verify_credentials.json').done(function(data) {
console.log(data)
var screen_name = data.screen_name
result.get({
url: '/1.1/statuses/user_timeline.json',
data: {
screen_name: screen_name
}
}).done(function(timeline) {
console.log(timeline)
}).error(function(error) {
console.log(error)
})
})
})
})
})