forked from microsoftgraph/nodejs-connect-rest-sample
-
Notifications
You must be signed in to change notification settings - Fork 2
/
emailer.js
80 lines (70 loc) · 4.78 KB
/
emailer.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
// Copyright (c) Microsoft. All rights reserved. Licensed under the MIT license. See full license at the bottom of this file.
// The contents of the outbound email message that will be sent to the user
var emailContent = "<html><head> <meta http-equiv=\'Content-Type\' content=\'text/html; charset=us-ascii\'> <title></title> </head><body style=\'font-family:calibri\'> <p>Congratulations {{name}},</p> <p>This is a message from the Office 365 Connect sample. You are well on your way to incorporating Office 365 services in your apps. </p> <h3>What’s next?</h3> <ul><li>Check out <a href=\'http://dev.office.com\' target=\'_blank\'>dev.office.com</a> to start building Office 365 apps today with all the latest tools, templates, and guidance to get started quickly.</li><li>Head over to the <a href=\'http://graph.microsoft.io/docs/api-reference\' target=\'blank\'>Microsoft Graph reference</a> to explore the rest of the APIs.</li><li>Browse other <a href=\'https://github.com/OfficeDev/\' target=\'_blank\'>samples on GitHub</a> to see more of the APIs in action.</li></ul> <h3>Give us feedback</h3> <ul><li>If you have any trouble running this sample, please <a href=\'\' target=\'_blank\'>log an issue</a>.</li><li>For general questions about the Office 365 APIs, post to <a href=\'http://stackoverflow.com/\' target=\'blank\'>Stack Overflow</a>. Make sure that your questions or comments are tagged with [office365].</li></ul><p>Thanks and happy coding!<br>Your Office 365 Development team </p> <div style=\'text-align:center; font-family:calibri\'> <table style=\'width:100%; font-family:calibri\'> <tbody> <tr> <td><a href=\'https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect\'>See on GitHub</a> </td> <td><a href=\'https://officespdev.uservoice.com/forums/224641-general/category/72301-documentation-guidance\'>Suggest on UserVoice</a> </td> <td><a href=\'http://twitter.com/share?text=I%20just%20started%20developing%20apps%20for%20%23Node.js%20using%20the%20%23Office365%20Connect%20app%20%40OfficeDev&url=https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect\'>Share on Twitter</a> </td> </tr> </tbody> </table> </div> </body> </html>";
/**
* Returns the outbound email message content with the supplied name populated in the text
* @param {string} name The proper noun to use when addressing the email
* @return {string} the formatted email body
*/
function getEmailContent(name) {
return emailContent.replace("{{name}}", name);
}
/**
* Wraps the email's message content in the expected [soon-to-deserialized JSON] format
* @param {string} content the message body of the email message
* @param {string} recipient the email address to whom this message will be sent
* @return the message object to send over the wire
*/
function wrapEmail(content, recipient) {
var emailAsPayload = {
Message: {
Subject: 'Welcome to Office 365 development with Node.js and the Office 365 Connect sample',
Body: {
ContentType: 'HTML',
Content: content
},
ToRecipients: [
{
EmailAddress: {
Address: recipient
}
}
]
},
SaveToSentItems: true
};
return emailAsPayload;
}
/**
* Delegating method to wrap the formatted email message into a POST-able object
* @param {string} name the name used to address the recipient
* @param {string} recipient the email address to which the connect email will be sent
*/
function generatePostBody(name, recipient) {
return wrapEmail(getEmailContent(name), recipient);
}
exports.generatePostBody = generatePostBody;
/*
######################################################################
O365-Nodejs-Microsoft-Graph-Connect, https://github.com/OfficeDev/O365-Nodejs-Microsoft-Graph-Connect
Copyright (c) Microsoft Corporation
All rights reserved.
MIT License:
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
######################################################################
*/