EmailBuilder.js 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813
  1. const _ = require('lodash')
  2. const settings = require('@overleaf/settings')
  3. const moment = require('moment')
  4. const EmailMessageHelper = require('./EmailMessageHelper')
  5. const StringHelper = require('../Helpers/StringHelper')
  6. const BaseWithHeaderEmailLayout = require('./Layouts/BaseWithHeaderEmailLayout')
  7. const SpamSafe = require('./SpamSafe')
  8. const ctaEmailBody = require('./Bodies/cta-email')
  9. const NoCTAEmailBody = require('./Bodies/NoCTAEmailBody')
  10. function _emailBodyPlainText(content, opts, ctaEmail) {
  11. let emailBody = `${content.greeting(opts, true)}`
  12. emailBody += `\r\n\r\n`
  13. emailBody += `${content.message(opts, true).join('\r\n\r\n')}`
  14. if (ctaEmail) {
  15. emailBody += `\r\n\r\n`
  16. emailBody += `${content.ctaText(opts, true)}: ${content.ctaURL(opts, true)}`
  17. }
  18. if (
  19. content.secondaryMessage(opts, true) &&
  20. content.secondaryMessage(opts, true).length > 0
  21. ) {
  22. emailBody += `\r\n\r\n`
  23. emailBody += `${content.secondaryMessage(opts, true).join('\r\n\r\n')}`
  24. }
  25. emailBody += `\r\n\r\n`
  26. emailBody += `Regards,\r\nThe ${settings.appName} Team - ${settings.siteUrl}`
  27. if (
  28. settings.email &&
  29. settings.email.template &&
  30. settings.email.template.customFooter
  31. ) {
  32. emailBody += `\r\n\r\n`
  33. emailBody += settings.email.template.customFooter
  34. }
  35. return emailBody
  36. }
  37. function ctaTemplate(content) {
  38. if (
  39. !content.ctaURL ||
  40. !content.ctaText ||
  41. !content.message ||
  42. !content.subject
  43. ) {
  44. throw new Error('missing required CTA email content')
  45. }
  46. if (!content.title) {
  47. content.title = () => {}
  48. }
  49. if (!content.greeting) {
  50. content.greeting = () => 'Hi,'
  51. }
  52. if (!content.secondaryMessage) {
  53. content.secondaryMessage = () => []
  54. }
  55. if (!content.gmailGoToAction) {
  56. content.gmailGoToAction = () => {}
  57. }
  58. return {
  59. subject(opts) {
  60. return content.subject(opts)
  61. },
  62. layout: BaseWithHeaderEmailLayout,
  63. plainTextTemplate(opts) {
  64. return _emailBodyPlainText(content, opts, true)
  65. },
  66. compiledTemplate(opts) {
  67. return ctaEmailBody({
  68. title: content.title(opts),
  69. greeting: content.greeting(opts),
  70. message: content.message(opts),
  71. secondaryMessage: content.secondaryMessage(opts),
  72. ctaText: content.ctaText(opts),
  73. ctaURL: content.ctaURL(opts),
  74. gmailGoToAction: content.gmailGoToAction(opts),
  75. StringHelper,
  76. })
  77. },
  78. }
  79. }
  80. function NoCTAEmailTemplate(content) {
  81. if (content.greeting == null) {
  82. content.greeting = () => 'Hi,'
  83. }
  84. if (!content.message) {
  85. throw new Error('missing message')
  86. }
  87. return {
  88. subject(opts) {
  89. return content.subject(opts)
  90. },
  91. layout: BaseWithHeaderEmailLayout,
  92. plainTextTemplate(opts) {
  93. return `\
  94. ${content.greeting(opts)}
  95. ${content.message(opts, true).join('\r\n\r\n')}
  96. Regards,
  97. The ${settings.appName} Team - ${settings.siteUrl}\
  98. `
  99. },
  100. compiledTemplate(opts) {
  101. return NoCTAEmailBody({
  102. title:
  103. typeof content.title === 'function' ? content.title(opts) : undefined,
  104. greeting: content.greeting(opts),
  105. message: content.message(opts),
  106. StringHelper,
  107. })
  108. },
  109. }
  110. }
  111. function buildEmail(templateName, opts) {
  112. const template = templates[templateName]
  113. opts.siteUrl = settings.siteUrl
  114. opts.body = template.compiledTemplate(opts)
  115. return {
  116. subject: template.subject(opts),
  117. html: template.layout(opts),
  118. text: template.plainTextTemplate && template.plainTextTemplate(opts),
  119. }
  120. }
  121. const templates = {}
  122. templates.registered = ctaTemplate({
  123. subject() {
  124. return `Activate your ${settings.appName} Account`
  125. },
  126. message(opts) {
  127. return [
  128. `Congratulations, you've just had an account created for you on ${
  129. settings.appName
  130. } with the email address '${_.escape(opts.to)}'.`,
  131. 'Click here to set your password and log in:',
  132. ]
  133. },
  134. secondaryMessage() {
  135. return [
  136. `If you have any questions or problems, please contact ${settings.adminEmail}`,
  137. ]
  138. },
  139. ctaText() {
  140. return 'Set password'
  141. },
  142. ctaURL(opts) {
  143. return opts.setNewPasswordUrl
  144. },
  145. })
  146. templates.canceledSubscription = ctaTemplate({
  147. subject() {
  148. return `${settings.appName} thoughts`
  149. },
  150. message() {
  151. return [
  152. `We are sorry to see you cancelled your ${settings.appName} premium subscription. Would you mind giving us some feedback on what the site is lacking at the moment via this quick survey?`,
  153. ]
  154. },
  155. secondaryMessage() {
  156. return ['Thank you in advance!']
  157. },
  158. ctaText() {
  159. return 'Leave Feedback'
  160. },
  161. ctaURL(opts) {
  162. return 'https://docs.google.com/forms/d/e/1FAIpQLSfa7z_s-cucRRXm70N4jEcSbFsZeb0yuKThHGQL8ySEaQzF0Q/viewform?usp=sf_link'
  163. },
  164. })
  165. templates.reactivatedSubscription = ctaTemplate({
  166. subject() {
  167. return `Subscription Reactivated - ${settings.appName}`
  168. },
  169. message(opts) {
  170. return ['Your subscription was reactivated successfully.']
  171. },
  172. ctaText() {
  173. return 'View Subscription Dashboard'
  174. },
  175. ctaURL(opts) {
  176. return `${settings.siteUrl}/user/subscription`
  177. },
  178. })
  179. templates.passwordResetRequested = ctaTemplate({
  180. subject() {
  181. return `Password Reset - ${settings.appName}`
  182. },
  183. title() {
  184. return 'Password Reset'
  185. },
  186. message() {
  187. return [`We got a request to reset your ${settings.appName} password.`]
  188. },
  189. secondaryMessage() {
  190. return [
  191. "If you ignore this message, your password won't be changed.",
  192. "If you didn't request a password reset, let us know.",
  193. ]
  194. },
  195. ctaText() {
  196. return 'Reset password'
  197. },
  198. ctaURL(opts) {
  199. return opts.setNewPasswordUrl
  200. },
  201. })
  202. templates.confirmEmail = ctaTemplate({
  203. subject() {
  204. return `Confirm Email - ${settings.appName}`
  205. },
  206. title() {
  207. return 'Confirm Email'
  208. },
  209. message(opts) {
  210. return [
  211. `Please confirm that you have added a new email, ${opts.to}, to your ${settings.appName} account.`,
  212. ]
  213. },
  214. secondaryMessage() {
  215. return [
  216. 'If you did not request this, please let us know at <a href="mailto:support@overleaf.com">support@overleaf.com</a>.',
  217. `If you have any questions or trouble confirming your email address, please get in touch with our support team at ${settings.adminEmail}.`,
  218. ]
  219. },
  220. ctaText() {
  221. return 'Confirm Email'
  222. },
  223. ctaURL(opts) {
  224. return opts.confirmEmailUrl
  225. },
  226. })
  227. templates.projectInvite = ctaTemplate({
  228. subject(opts) {
  229. const safeName = SpamSafe.isSafeProjectName(opts.project.name)
  230. const safeEmail = SpamSafe.isSafeEmail(opts.owner.email)
  231. if (safeName && safeEmail) {
  232. return `"${_.escape(opts.project.name)}" — shared by ${_.escape(
  233. opts.owner.email
  234. )}`
  235. }
  236. if (safeName) {
  237. return `${settings.appName} project shared with you — "${_.escape(
  238. opts.project.name
  239. )}"`
  240. }
  241. if (safeEmail) {
  242. return `${_.escape(opts.owner.email)} shared an ${
  243. settings.appName
  244. } project with you`
  245. }
  246. return `An ${settings.appName} project has been shared with you`
  247. },
  248. title(opts) {
  249. return 'Project Invite'
  250. },
  251. greeting(opts) {
  252. return ''
  253. },
  254. message(opts, isPlainText) {
  255. // build message depending on spam-safe variables
  256. const message = [`You have been invited to an ${settings.appName} project.`]
  257. if (SpamSafe.isSafeProjectName(opts.project.name)) {
  258. message.push('<br/> Project:')
  259. message.push(`<b>${_.escape(opts.project.name)}</b>`)
  260. }
  261. if (SpamSafe.isSafeEmail(opts.owner.email)) {
  262. message.push(`<br/> Shared by:`)
  263. message.push(`<b>${_.escape(opts.owner.email)}</b>`)
  264. }
  265. if (message.length === 1) {
  266. message.push('<br/> Please view the project to find out more.')
  267. }
  268. return message.map(m => {
  269. return EmailMessageHelper.cleanHTML(m, isPlainText)
  270. })
  271. },
  272. ctaText() {
  273. return 'View project'
  274. },
  275. ctaURL(opts) {
  276. return opts.inviteUrl
  277. },
  278. gmailGoToAction(opts) {
  279. return {
  280. target: opts.inviteUrl,
  281. name: 'View project',
  282. description: `Join ${_.escape(
  283. SpamSafe.safeProjectName(opts.project.name, 'project')
  284. )} at ${settings.appName}`,
  285. }
  286. },
  287. })
  288. templates.reconfirmEmail = ctaTemplate({
  289. subject() {
  290. return `Reconfirm Email - ${settings.appName}`
  291. },
  292. title() {
  293. return 'Reconfirm Email'
  294. },
  295. message(opts) {
  296. return [
  297. `Please reconfirm your email address, ${opts.to}, on your ${settings.appName} account.`,
  298. ]
  299. },
  300. secondaryMessage() {
  301. return [
  302. 'If you did not request this, you can simply ignore this message.',
  303. `If you have any questions or trouble confirming your email address, please get in touch with our support team at ${settings.adminEmail}.`,
  304. ]
  305. },
  306. ctaText() {
  307. return 'Reconfirm Email'
  308. },
  309. ctaURL(opts) {
  310. return opts.confirmEmailUrl
  311. },
  312. })
  313. templates.verifyEmailToJoinTeam = ctaTemplate({
  314. subject(opts) {
  315. return `${_.escape(
  316. _formatUserNameAndEmail(opts.inviter, 'A collaborator')
  317. )} has invited you to join a group subscription on ${settings.appName}`
  318. },
  319. title(opts) {
  320. return `${_.escape(
  321. _formatUserNameAndEmail(opts.inviter, 'A collaborator')
  322. )} has invited you to join a group subscription on ${settings.appName}`
  323. },
  324. message(opts) {
  325. return [
  326. `Please click the button below to join the group subscription and enjoy the benefits of an upgraded ${settings.appName} account.`,
  327. ]
  328. },
  329. ctaText(opts) {
  330. return 'Join now'
  331. },
  332. ctaURL(opts) {
  333. return opts.acceptInviteUrl
  334. },
  335. })
  336. templates.verifyEmailToJoinManagedUsers = ctaTemplate({
  337. subject(opts) {
  338. return `${
  339. opts.reminder ? 'Reminder: ' : ''
  340. }You’ve been invited by ${_.escape(
  341. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  342. )} to join an ${settings.appName} group subscription.`
  343. },
  344. title(opts) {
  345. return `${
  346. opts.reminder ? 'Reminder: ' : ''
  347. }You’ve been invited by ${_.escape(
  348. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  349. )} to join an ${settings.appName} group subscription.`
  350. },
  351. message(opts) {
  352. return [
  353. `By joining this group, you'll have access to ${settings.appName} premium features such as additional collaborators, greater maximum compile time, and real-time track changes.`,
  354. ]
  355. },
  356. secondaryMessage(opts, isPlainText) {
  357. const changeProjectOwnerLink = EmailMessageHelper.displayLink(
  358. 'change project owner',
  359. `${settings.siteUrl}/learn/how-to/How_to_Transfer_Project_Ownership`,
  360. isPlainText
  361. )
  362. return [
  363. `<b>User accounts in this group are managed by ${_.escape(
  364. _formatUserNameAndEmail(opts.admin, 'an admin')
  365. )}</b>`,
  366. `If you accept, you’ll transfer the management of your ${settings.appName} account to the owner of the group subscription, who will then have admin rights over your account and control over your stuff.`,
  367. `If you have personal projects in your ${settings.appName} account that you want to keep separate, that’s not a problem. You can set up another account under a personal email address and change the ownership of your personal projects to the new account. Find out how to ${changeProjectOwnerLink}.`,
  368. ]
  369. },
  370. ctaURL(opts) {
  371. return opts.acceptInviteUrl
  372. },
  373. ctaText(opts) {
  374. return 'Accept invitation'
  375. },
  376. greeting() {
  377. return ''
  378. },
  379. })
  380. templates.inviteNewUserToJoinManagedUsers = ctaTemplate({
  381. subject(opts) {
  382. return `${
  383. opts.reminder ? 'Reminder: ' : ''
  384. }You’ve been invited by ${_.escape(
  385. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  386. )} to join an ${settings.appName} group subscription.`
  387. },
  388. title(opts) {
  389. return `${
  390. opts.reminder ? 'Reminder: ' : ''
  391. }You’ve been invited by ${_.escape(
  392. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  393. )} to join an ${settings.appName} group subscription.`
  394. },
  395. message(opts) {
  396. return ['']
  397. },
  398. secondaryMessage(opts) {
  399. return [
  400. `User accounts in this group are managed by ${_.escape(
  401. _formatUserNameAndEmail(opts.admin, 'an admin')
  402. )}.`,
  403. `If you accept, the owner of the group subscription will have admin rights over your account and control over your stuff.`,
  404. `<b>What is ${settings.appName}?</b>`,
  405. `${settings.appName} is the collaborative online LaTeX editor loved by researchers and technical writers. With thousands of ready-to-use templates and an array of LaTeX learning resources you’ll be up and running in no time.`,
  406. ]
  407. },
  408. ctaURL(opts) {
  409. return opts.acceptInviteUrl
  410. },
  411. ctaText(opts) {
  412. return 'Accept invitation'
  413. },
  414. greeting() {
  415. return ''
  416. },
  417. })
  418. templates.managedUsersEnabledSSO = ctaTemplate({
  419. subject(opts) {
  420. const subjectPrefix = opts.reminder ? 'Reminder: ' : 'Action required: '
  421. return `${subjectPrefix}Authenticate your Overleaf account`
  422. },
  423. title(opts) {
  424. const titlePrefix = opts.reminder ? 'Reminder: ' : ''
  425. return `${titlePrefix}Single sign-on enabled`
  426. },
  427. message(opts) {
  428. return [
  429. `Hi,
  430. <div>
  431. Your group administrator has enabled single sign-on for your group.
  432. </div>
  433. </br>
  434. <div>
  435. <strong>What does this mean for you?</strong>
  436. </div>
  437. </br>
  438. <div>
  439. You won't need to remember a separate email address and password to sign in to Overleaf.
  440. All you need to do is authenticate your existing Overleaf account with your SSO provider.
  441. </div>
  442. `,
  443. ]
  444. },
  445. secondaryMessage(opts) {
  446. return [``]
  447. },
  448. ctaURL(opts) {
  449. return opts.authenticateWithSSO
  450. },
  451. ctaText(opts) {
  452. return 'Authenticate with SSO'
  453. },
  454. greeting() {
  455. return ''
  456. },
  457. })
  458. templates.managedUsersDisabledSSO = ctaTemplate({
  459. subject(opts) {
  460. return `Action required: Set your Overleaf password`
  461. },
  462. title(opts) {
  463. return `Single sign-on disabled`
  464. },
  465. message(opts) {
  466. return [
  467. `Hi,
  468. <div>
  469. Your group administrator has disabled single sign-on for your group.
  470. </div>
  471. </br>
  472. <div>
  473. <strong>What does this mean for you?</strong>
  474. </div>
  475. </br>
  476. <div>
  477. You now need an email address and password to sign in to your Overleaf account.
  478. </div>
  479. `,
  480. ]
  481. },
  482. secondaryMessage(opts) {
  483. return [``]
  484. },
  485. ctaURL(opts) {
  486. return opts.setNewPasswordUrl
  487. },
  488. ctaText(opts) {
  489. return 'Set your new password'
  490. },
  491. greeting() {
  492. return ''
  493. },
  494. })
  495. templates.surrenderAccountForManagedUsers = ctaTemplate({
  496. subject(opts) {
  497. const admin = _.escape(_formatUserNameAndEmail(opts.admin, 'an admin'))
  498. const toGroupName = opts.groupName ? ` to ${opts.groupName}` : ''
  499. return `${
  500. opts.reminder ? 'Reminder: ' : ''
  501. }You’ve been invited by ${admin} to transfer management of your ${
  502. settings.appName
  503. } account${toGroupName}`
  504. },
  505. title(opts) {
  506. const admin = _.escape(_formatUserNameAndEmail(opts.admin, 'an admin'))
  507. const toGroupName = opts.groupName ? ` to ${opts.groupName}` : ''
  508. return `${
  509. opts.reminder ? 'Reminder: ' : ''
  510. }You’ve been invited by ${admin} to transfer management of your ${
  511. settings.appName
  512. } account${toGroupName}`
  513. },
  514. message(opts, isPlainText) {
  515. const admin = _.escape(_formatUserNameAndEmail(opts.admin, 'an admin'))
  516. const managedUsersLink = EmailMessageHelper.displayLink(
  517. 'user account management',
  518. `${settings.siteUrl}/learn/how-to/Understanding_Managed_Overleaf_Accounts`,
  519. isPlainText
  520. )
  521. return [
  522. `Your ${settings.appName} account ${_.escape(
  523. opts.to
  524. )} is part of ${admin}'s group. They’ve now enabled ${managedUsersLink} for the group. This will ensure that projects aren’t lost when someone leaves the group.`,
  525. ]
  526. },
  527. secondaryMessage(opts, isPlainText) {
  528. const transferProjectOwnershipLink = EmailMessageHelper.displayLink(
  529. 'change project owner',
  530. `${settings.siteUrl}/learn/how-to/How_to_Transfer_Project_Ownership`,
  531. isPlainText
  532. )
  533. return [
  534. `<b>What does this mean for you?</b>`,
  535. `If you accept, you’ll transfer the management of your ${settings.appName} account to the owner of the group subscription, who will then have admin rights over your account and control over your stuff.`,
  536. `If you have personal projects in your ${settings.appName} account that you want to keep separate, that’s not a problem. You can set up another account under a personal email address and change the ownership of your personal projects to the new account. Find out how to ${transferProjectOwnershipLink}.`,
  537. `If you think this invitation has been sent in error please contact your group administrator.`,
  538. ]
  539. },
  540. ctaURL(opts) {
  541. return opts.acceptInviteUrl
  542. },
  543. ctaText(opts) {
  544. return 'Accept invitation'
  545. },
  546. greeting() {
  547. return ''
  548. },
  549. })
  550. templates.testEmail = ctaTemplate({
  551. subject() {
  552. return `A Test Email from ${settings.appName}`
  553. },
  554. title() {
  555. return `A Test Email from ${settings.appName}`
  556. },
  557. greeting() {
  558. return 'Hi,'
  559. },
  560. message() {
  561. return [`This is a test Email from ${settings.appName}`]
  562. },
  563. ctaText() {
  564. return `Open ${settings.appName}`
  565. },
  566. ctaURL() {
  567. return settings.siteUrl
  568. },
  569. })
  570. templates.ownershipTransferConfirmationPreviousOwner = NoCTAEmailTemplate({
  571. subject(opts) {
  572. return `Project ownership transfer - ${settings.appName}`
  573. },
  574. title(opts) {
  575. const projectName = _.escape(
  576. SpamSafe.safeProjectName(opts.project.name, 'Your project')
  577. )
  578. return `${projectName} - Owner change`
  579. },
  580. message(opts, isPlainText) {
  581. const nameAndEmail = _.escape(
  582. _formatUserNameAndEmail(opts.newOwner, 'a collaborator')
  583. )
  584. const projectName = _.escape(
  585. SpamSafe.safeProjectName(opts.project.name, 'your project')
  586. )
  587. const projectNameDisplay = isPlainText
  588. ? projectName
  589. : `<b>${projectName}</b>`
  590. return [
  591. `As per your request, we have made ${nameAndEmail} the owner of ${projectNameDisplay}.`,
  592. `If you haven't asked to change the owner of ${projectNameDisplay}, please get in touch with us via ${settings.adminEmail}.`,
  593. ]
  594. },
  595. })
  596. templates.ownershipTransferConfirmationNewOwner = ctaTemplate({
  597. subject(opts) {
  598. return `Project ownership transfer - ${settings.appName}`
  599. },
  600. title(opts) {
  601. const projectName = _.escape(
  602. SpamSafe.safeProjectName(opts.project.name, 'Your project')
  603. )
  604. return `${projectName} - Owner change`
  605. },
  606. message(opts, isPlainText) {
  607. const nameAndEmail = _.escape(
  608. _formatUserNameAndEmail(opts.previousOwner, 'A collaborator')
  609. )
  610. const projectName = _.escape(
  611. SpamSafe.safeProjectName(opts.project.name, 'a project')
  612. )
  613. const projectNameEmphasized = isPlainText
  614. ? projectName
  615. : `<b>${projectName}</b>`
  616. return [
  617. `${nameAndEmail} has made you the owner of ${projectNameEmphasized}. You can now manage ${projectName} sharing settings.`,
  618. ]
  619. },
  620. ctaText(opts) {
  621. return 'View project'
  622. },
  623. ctaURL(opts) {
  624. const projectUrl = `${
  625. settings.siteUrl
  626. }/project/${opts.project._id.toString()}`
  627. return projectUrl
  628. },
  629. })
  630. templates.userOnboardingEmail = NoCTAEmailTemplate({
  631. subject(opts) {
  632. return `Getting more out of ${settings.appName}`
  633. },
  634. greeting(opts) {
  635. return ''
  636. },
  637. title(opts) {
  638. return `Getting more out of ${settings.appName}`
  639. },
  640. message(opts, isPlainText) {
  641. const learnLatexLink = EmailMessageHelper.displayLink(
  642. 'Learn LaTeX in 30 minutes',
  643. `${settings.siteUrl}/learn/latex/Learn_LaTeX_in_30_minutes?utm_source=overleaf&utm_medium=email&utm_campaign=onboarding`,
  644. isPlainText
  645. )
  646. const templatesLinks = EmailMessageHelper.displayLink(
  647. 'Find a beautiful template',
  648. `${settings.siteUrl}/latex/templates?utm_source=overleaf&utm_medium=email&utm_campaign=onboarding`,
  649. isPlainText
  650. )
  651. const collaboratorsLink = EmailMessageHelper.displayLink(
  652. 'Work with your collaborators',
  653. `${settings.siteUrl}/learn/how-to/Sharing_a_project?utm_source=overleaf&utm_medium=email&utm_campaign=onboarding`,
  654. isPlainText
  655. )
  656. const siteLink = EmailMessageHelper.displayLink(
  657. 'www.overleaf.com',
  658. settings.siteUrl,
  659. isPlainText
  660. )
  661. const userSettingsLink = EmailMessageHelper.displayLink(
  662. 'here',
  663. `${settings.siteUrl}/user/email-preferences`,
  664. isPlainText
  665. )
  666. const onboardingSurveyLink = EmailMessageHelper.displayLink(
  667. 'Join our user feedback program',
  668. 'https://forms.gle/DB7pdk2B1VFQqVVB9',
  669. isPlainText
  670. )
  671. return [
  672. `Thanks for signing up for ${settings.appName} recently. We hope you've been finding it useful! Here are some key features to help you get the most out of the service:`,
  673. `${learnLatexLink}: In this tutorial we provide a quick and easy first introduction to LaTeX with no prior knowledge required. By the time you are finished, you will have written your first LaTeX document!`,
  674. `${templatesLinks}: If you're looking for a template or example to get started, we've a large selection available in our template gallery, including CVs, project reports, journal articles and more.`,
  675. `${collaboratorsLink}: One of the key features of Overleaf is the ability to share projects and collaborate on them with other users. Find out how to share your projects with your colleagues in this quick how-to guide.`,
  676. `${onboardingSurveyLink} to help us make Overleaf even better!`,
  677. 'Thanks again for using Overleaf :)',
  678. `Lee`,
  679. `Lee Shalit<br />CEO<br />${siteLink}<hr>`,
  680. `You're receiving this email because you've recently signed up for an Overleaf account. If you've previously subscribed to emails about product offers and company news and events, you can unsubscribe ${userSettingsLink}.`,
  681. ]
  682. },
  683. })
  684. templates.securityAlert = NoCTAEmailTemplate({
  685. subject(opts) {
  686. return `Overleaf security note: ${opts.action}`
  687. },
  688. title(opts) {
  689. return opts.action.charAt(0).toUpperCase() + opts.action.slice(1)
  690. },
  691. message(opts, isPlainText) {
  692. const dateFormatted = moment().format('dddd D MMMM YYYY')
  693. const timeFormatted = moment().format('HH:mm')
  694. const helpLink = EmailMessageHelper.displayLink(
  695. 'quick guide',
  696. `${settings.siteUrl}/learn/how-to/Keeping_your_account_secure`,
  697. isPlainText
  698. )
  699. const actionDescribed = EmailMessageHelper.cleanHTML(
  700. opts.actionDescribed,
  701. isPlainText
  702. )
  703. if (!opts.message) {
  704. opts.message = []
  705. }
  706. const message = opts.message.map(m => {
  707. return EmailMessageHelper.cleanHTML(m, isPlainText)
  708. })
  709. return [
  710. `We are writing to let you know that ${actionDescribed} on ${dateFormatted} at ${timeFormatted} GMT.`,
  711. ...message,
  712. `If this was you, you can ignore this email.`,
  713. `If this was not you, we recommend getting in touch with our support team at ${settings.adminEmail} to report this as potentially suspicious activity on your account.`,
  714. `We also encourage you to read our ${helpLink} to keeping your ${settings.appName} account safe.`,
  715. ]
  716. },
  717. })
  718. templates.SAMLDataCleared = ctaTemplate({
  719. subject(opts) {
  720. return `Institutional Login No Longer Linked - ${settings.appName}`
  721. },
  722. title(opts) {
  723. return 'Institutional Login No Longer Linked'
  724. },
  725. message(opts, isPlainText) {
  726. return [
  727. `We're writing to let you know that due to a bug on our end, we've had to temporarily disable logging into your ${settings.appName} through your institution.`,
  728. `To get it going again, you'll need to relink your institutional email address to your ${settings.appName} account via your settings.`,
  729. ]
  730. },
  731. secondaryMessage() {
  732. return [
  733. `If you ordinarily log in to your ${settings.appName} account through your institution, you may need to set or reset your password to regain access to your account first.`,
  734. 'This bug did not affect the security of any accounts, but it may have affected license entitlements for a small number of users. We are sorry for any inconvenience that this may cause for you.',
  735. `If you have any questions, please get in touch with our support team at ${settings.adminEmail} or by replying to this email.`,
  736. ]
  737. },
  738. ctaText(opts) {
  739. return 'Update my Emails and Affiliations'
  740. },
  741. ctaURL(opts) {
  742. return `${settings.siteUrl}/user/settings`
  743. },
  744. })
  745. function _formatUserNameAndEmail(user, placeholder) {
  746. if (user.first_name && user.last_name) {
  747. const fullName = `${user.first_name} ${user.last_name}`
  748. if (SpamSafe.isSafeUserName(fullName)) {
  749. if (SpamSafe.isSafeEmail(user.email)) {
  750. return `${fullName} (${user.email})`
  751. } else {
  752. return fullName
  753. }
  754. }
  755. }
  756. return SpamSafe.safeEmail(user.email, placeholder)
  757. }
  758. module.exports = {
  759. templates,
  760. ctaTemplate,
  761. NoCTAEmailTemplate,
  762. buildEmail,
  763. }