EmailBuilder.mjs 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. import _ from 'lodash'
  2. import settings from '@overleaf/settings'
  3. import moment from 'moment'
  4. import EmailMessageHelper from './EmailMessageHelper.mjs'
  5. import StringHelper from '../Helpers/StringHelper.mjs'
  6. import BaseEmailLayout from './Layouts/BaseEmailLayout.mjs'
  7. import SpamSafe from './SpamSafe.mjs'
  8. import ctaEmailBody from './Bodies/cta-email.mjs'
  9. import NoCTAEmailBody from './Bodies/NoCTAEmailBody.mjs'
  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. const footerMessage = content.footerMessage(opts, true)
  36. if (footerMessage) {
  37. emailBody += `\r\n\r\n`
  38. emailBody += footerMessage
  39. }
  40. return emailBody
  41. }
  42. function ctaTemplate(content) {
  43. if (
  44. !content.ctaURL ||
  45. !content.ctaText ||
  46. !content.message ||
  47. !content.subject
  48. ) {
  49. throw new Error('missing required CTA email content')
  50. }
  51. if (!content.title) {
  52. content.title = () => {}
  53. }
  54. if (!content.greeting) {
  55. content.greeting = () => 'Hi,'
  56. }
  57. if (!content.secondaryMessage) {
  58. content.secondaryMessage = () => []
  59. }
  60. if (!content.gmailGoToAction) {
  61. content.gmailGoToAction = () => {}
  62. }
  63. if (!content.footerMessage) {
  64. content.footerMessage = () => {}
  65. }
  66. return {
  67. subject(opts) {
  68. return content.subject(opts)
  69. },
  70. layout(opts) {
  71. return BaseEmailLayout(opts)
  72. },
  73. footerMessage(opts) {
  74. return content.footerMessage(opts)
  75. },
  76. plainTextTemplate(opts) {
  77. return _emailBodyPlainText(content, opts, true)
  78. },
  79. compiledTemplate(opts) {
  80. return ctaEmailBody({
  81. title: content.title(opts),
  82. greeting: content.greeting(opts),
  83. message: content.message(opts),
  84. secondaryMessage: content.secondaryMessage(opts),
  85. ctaText: content.ctaText(opts),
  86. ctaURL: content.ctaURL(opts),
  87. gmailGoToAction: content.gmailGoToAction(opts),
  88. StringHelper,
  89. })
  90. },
  91. }
  92. }
  93. function NoCTAEmailTemplate(content) {
  94. if (content.greeting == null) {
  95. content.greeting = () => 'Hi,'
  96. }
  97. if (!content.message) {
  98. throw new Error('missing message')
  99. }
  100. return {
  101. subject(opts) {
  102. return content.subject(opts)
  103. },
  104. layout(opts) {
  105. return BaseEmailLayout(opts)
  106. },
  107. plainTextTemplate(opts) {
  108. return `\
  109. ${content.greeting(opts)}
  110. ${content.message(opts, true).join('\r\n\r\n')}
  111. Regards,
  112. The ${settings.appName} Team - ${settings.siteUrl}\
  113. `
  114. },
  115. compiledTemplate(opts) {
  116. return NoCTAEmailBody({
  117. title:
  118. typeof content.title === 'function' ? content.title(opts) : undefined,
  119. greeting: content.greeting(opts),
  120. highlightedText:
  121. typeof content.highlightedText === 'function'
  122. ? content.highlightedText(opts)
  123. : undefined,
  124. message: content.message(opts),
  125. StringHelper,
  126. })
  127. },
  128. }
  129. }
  130. function buildEmail(templateName, opts) {
  131. const template = templates[templateName]
  132. opts.body = template.compiledTemplate(opts)
  133. opts.footerMessage = template.footerMessage
  134. ? template.footerMessage(opts)
  135. : ''
  136. return {
  137. subject: template.subject(opts),
  138. html: template.layout(opts),
  139. text: template.plainTextTemplate && template.plainTextTemplate(opts),
  140. }
  141. }
  142. const templates = {}
  143. templates.registered = ctaTemplate({
  144. subject() {
  145. return `Activate your ${settings.appName} Account`
  146. },
  147. message(opts) {
  148. return [
  149. `Congratulations, you've just had an account created for you on ${
  150. settings.appName
  151. } with the email address '${_.escape(opts.to)}'.`,
  152. 'Click here to set your password and log in:',
  153. ]
  154. },
  155. secondaryMessage() {
  156. return [
  157. `If you have any questions or problems, please contact ${settings.adminEmail}`,
  158. ]
  159. },
  160. ctaText() {
  161. return 'Set password'
  162. },
  163. ctaURL(opts) {
  164. return opts.setNewPasswordUrl
  165. },
  166. })
  167. templates.canceledSubscription = ctaTemplate({
  168. subject() {
  169. return `${settings.appName} thoughts`
  170. },
  171. message() {
  172. return [
  173. `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?`,
  174. ]
  175. },
  176. secondaryMessage() {
  177. return ['Thank you in advance!']
  178. },
  179. ctaText() {
  180. return 'Leave feedback'
  181. },
  182. ctaURL(opts) {
  183. return 'https://docs.google.com/forms/d/e/1FAIpQLSfa7z_s-cucRRXm70N4jEcSbFsZeb0yuKThHGQL8ySEaQzF0Q/viewform?usp=sf_link'
  184. },
  185. })
  186. templates.canceledSubscriptionOrAddOn = ctaTemplate({
  187. subject() {
  188. return `${settings.appName} thoughts`
  189. },
  190. message() {
  191. return [
  192. `We are sorry to see you cancelled your ${settings.appName} subscription. Would you mind giving us some feedback on what the site is lacking at the moment via this quick survey?`,
  193. ]
  194. },
  195. secondaryMessage() {
  196. return ['Thank you in advance!']
  197. },
  198. ctaText() {
  199. return 'Leave feedback'
  200. },
  201. ctaURL(opts) {
  202. return 'https://digitalscience.qualtrics.com/jfe/form/SV_2n2aSlWgvoxXdGK'
  203. },
  204. })
  205. templates.reactivatedSubscription = ctaTemplate({
  206. subject() {
  207. return `Subscription Reactivated - ${settings.appName}`
  208. },
  209. message(opts) {
  210. return ['Your subscription was reactivated successfully.']
  211. },
  212. ctaText() {
  213. return 'View Subscription Dashboard'
  214. },
  215. ctaURL(opts) {
  216. return `${settings.siteUrl}/user/subscription`
  217. },
  218. })
  219. templates.passwordResetRequested = ctaTemplate({
  220. subject() {
  221. return `Password Reset - ${settings.appName}`
  222. },
  223. title() {
  224. return 'Password Reset'
  225. },
  226. message() {
  227. return [`We got a request to reset your ${settings.appName} password.`]
  228. },
  229. secondaryMessage() {
  230. return [
  231. "If you ignore this message, your password won't be changed.",
  232. "If you didn't request a password reset, let us know.",
  233. ]
  234. },
  235. ctaText() {
  236. return 'Reset password'
  237. },
  238. ctaURL(opts) {
  239. return opts.setNewPasswordUrl
  240. },
  241. })
  242. templates.confirmCode = NoCTAEmailTemplate({
  243. greeting(opts) {
  244. return ''
  245. },
  246. subject(opts) {
  247. return `Confirm your email address on Overleaf (${opts.confirmCode})`
  248. },
  249. title(opts) {
  250. return 'Confirm your email address'
  251. },
  252. message(opts, isPlainText) {
  253. const msg = opts.welcomeUser
  254. ? [
  255. `Welcome to Overleaf! We're so glad you joined us.`,
  256. 'Use this 6-digit confirmation code to finish your setup.',
  257. ]
  258. : ['Use this 6-digit code to confirm your email address.']
  259. if (isPlainText && opts.confirmCode) {
  260. msg.push(opts.confirmCode)
  261. }
  262. return msg
  263. },
  264. highlightedText(opts) {
  265. return opts.confirmCode
  266. },
  267. })
  268. templates.projectInvite = ctaTemplate({
  269. subject(opts) {
  270. const safeName = SpamSafe.isSafeProjectName(opts.project.name)
  271. const safeEmail = SpamSafe.isSafeEmail(opts.owner.email)
  272. if (safeName && safeEmail) {
  273. return `"${opts.project.name}" — shared by ${_.escape(opts.owner.email)}`
  274. }
  275. if (safeName) {
  276. return `${settings.appName} project shared with you — "${_.escape(
  277. opts.project.name
  278. )}"`
  279. }
  280. if (safeEmail) {
  281. return `${_.escape(opts.owner.email)} shared an ${
  282. settings.appName
  283. } project with you`
  284. }
  285. return `An ${settings.appName} project has been shared with you`
  286. },
  287. title(opts) {
  288. return 'Project Invite'
  289. },
  290. greeting(opts) {
  291. return ''
  292. },
  293. message(opts, isPlainText) {
  294. // build message depending on spam-safe variables
  295. const message = [`You have been invited to an ${settings.appName} project.`]
  296. if (SpamSafe.isSafeProjectName(opts.project.name)) {
  297. message.push('<br/> Project:')
  298. message.push(`<b>${_.escape(opts.project.name)}</b>`)
  299. }
  300. if (SpamSafe.isSafeEmail(opts.owner.email)) {
  301. message.push(`<br/> Shared by:`)
  302. message.push(`<b>${_.escape(opts.owner.email)}</b>`)
  303. }
  304. if (message.length === 1) {
  305. message.push('<br/> Please view the project to find out more.')
  306. }
  307. return message.map(m => {
  308. return EmailMessageHelper.cleanHTML(m, isPlainText)
  309. })
  310. },
  311. ctaText() {
  312. return 'View project'
  313. },
  314. ctaURL(opts) {
  315. return opts.inviteUrl
  316. },
  317. gmailGoToAction(opts) {
  318. return {
  319. target: opts.inviteUrl,
  320. name: 'View project',
  321. description: `Join ${_.escape(
  322. SpamSafe.safeProjectName(opts.project.name, 'project')
  323. )} at ${settings.appName}`,
  324. }
  325. },
  326. })
  327. templates.verifyEmailToJoinTeam = ctaTemplate({
  328. subject(opts) {
  329. return `${opts.reminder ? 'Reminder: ' : ''}${_.escape(
  330. _formatUserNameAndEmail(opts.inviter, 'A collaborator')
  331. )} has invited you to join a group subscription on ${settings.appName}`
  332. },
  333. title(opts) {
  334. return `${opts.reminder ? 'Reminder: ' : ''}${_.escape(
  335. _formatUserNameAndEmail(opts.inviter, 'A collaborator')
  336. )} has invited you to join a group subscription on ${settings.appName}`
  337. },
  338. message(opts) {
  339. return [
  340. `Please click the button below to join the group subscription and enjoy the benefits of an upgraded ${settings.appName} account.`,
  341. ]
  342. },
  343. ctaText(opts) {
  344. return 'Join now'
  345. },
  346. ctaURL(opts) {
  347. return opts.acceptInviteUrl
  348. },
  349. })
  350. templates.verifyEmailToJoinManagedUsers = ctaTemplate({
  351. subject(opts) {
  352. return `${
  353. opts.reminder ? 'Reminder: ' : ''
  354. }You’ve been invited by ${_.escape(
  355. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  356. )} to join an ${settings.appName} group subscription.`
  357. },
  358. title(opts) {
  359. return `${
  360. opts.reminder ? 'Reminder: ' : ''
  361. }You’ve been invited by ${_.escape(
  362. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  363. )} to join an ${settings.appName} group subscription.`
  364. },
  365. message(opts) {
  366. return [
  367. `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.`,
  368. ]
  369. },
  370. secondaryMessage(opts, isPlainText) {
  371. const changeProjectOwnerLink = EmailMessageHelper.displayLink(
  372. 'change project owner',
  373. `${settings.siteUrl}/learn/how-to/How_to_Transfer_Project_Ownership`,
  374. isPlainText
  375. )
  376. return [
  377. `<b>User accounts in this group are managed by ${_.escape(
  378. _formatUserNameAndEmail(opts.admin, 'an admin')
  379. )}</b>`,
  380. `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.`,
  381. `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}.`,
  382. ]
  383. },
  384. ctaURL(opts) {
  385. return opts.acceptInviteUrl
  386. },
  387. ctaText(opts) {
  388. return 'Accept invitation'
  389. },
  390. greeting() {
  391. return ''
  392. },
  393. })
  394. templates.inviteNewUserToJoinManagedUsers = ctaTemplate({
  395. subject(opts) {
  396. return `${
  397. opts.reminder ? 'Reminder: ' : ''
  398. }You’ve been invited by ${_.escape(
  399. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  400. )} to join an ${settings.appName} group subscription.`
  401. },
  402. title(opts) {
  403. return `${
  404. opts.reminder ? 'Reminder: ' : ''
  405. }You’ve been invited by ${_.escape(
  406. _formatUserNameAndEmail(opts.inviter, 'a collaborator')
  407. )} to join an ${settings.appName} group subscription.`
  408. },
  409. message(opts) {
  410. return ['']
  411. },
  412. secondaryMessage(opts) {
  413. return [
  414. `<b>User accounts in this group are managed by ${_.escape(
  415. _formatUserNameAndEmail(opts.admin, 'an admin')
  416. )}.</b>`,
  417. `If you accept, the owner of the group subscription will have admin rights over your account and control over your stuff.`,
  418. `<b>What is ${settings.appName}?</b>`,
  419. `${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.`,
  420. ]
  421. },
  422. ctaURL(opts) {
  423. return opts.acceptInviteUrl
  424. },
  425. ctaText(opts) {
  426. return 'Accept invitation'
  427. },
  428. greeting() {
  429. return ''
  430. },
  431. })
  432. templates.groupSSOLinkingInvite = ctaTemplate({
  433. subject(opts) {
  434. const subjectPrefix = opts.reminder ? 'Reminder: ' : 'Action required: '
  435. return `${subjectPrefix}Authenticate your Overleaf account`
  436. },
  437. title(opts) {
  438. const titlePrefix = opts.reminder ? 'Reminder: ' : ''
  439. return `${titlePrefix}Single sign-on enabled`
  440. },
  441. message(opts) {
  442. return [
  443. `Hi,
  444. <div>
  445. Your group administrator has enabled single sign-on for your group.
  446. </div>
  447. </br>
  448. <div>
  449. <strong>What does this mean for you?</strong>
  450. </div>
  451. </br>
  452. <div>
  453. You won't need to remember a separate email address and password to sign in to Overleaf.
  454. All you need to do is authenticate your existing Overleaf account with your SSO provider.
  455. </div>
  456. `,
  457. ]
  458. },
  459. secondaryMessage(opts) {
  460. return [``]
  461. },
  462. ctaURL(opts) {
  463. return opts.authenticateWithSSO
  464. },
  465. ctaText(opts) {
  466. return 'Authenticate with SSO'
  467. },
  468. greeting() {
  469. return ''
  470. },
  471. })
  472. templates.groupSSOReauthenticate = ctaTemplate({
  473. subject(opts) {
  474. return 'Action required: Reauthenticate your Overleaf account'
  475. },
  476. title(opts) {
  477. return 'Action required: Reauthenticate SSO'
  478. },
  479. message(opts) {
  480. return [
  481. `Hi,
  482. <div>
  483. Single sign-on for your Overleaf group has been updated.
  484. This means you need to reauthenticate your Overleaf account with your group’s SSO provider.
  485. </div>
  486. `,
  487. ]
  488. },
  489. secondaryMessage(opts) {
  490. if (!opts.isManagedUser) {
  491. return ['']
  492. } else {
  493. const passwordResetUrl = `${settings.siteUrl}/user/password/reset`
  494. return [
  495. `If you’re not currently logged in to Overleaf, you'll need to <a href="${passwordResetUrl}">set a new password</a> to reauthenticate.`,
  496. ]
  497. }
  498. },
  499. ctaURL(opts) {
  500. return opts.authenticateWithSSO
  501. },
  502. ctaText(opts) {
  503. return 'Reauthenticate now'
  504. },
  505. greeting() {
  506. return ''
  507. },
  508. })
  509. templates.groupSSODisabled = ctaTemplate({
  510. subject(opts) {
  511. if (opts.userIsManaged) {
  512. return `Action required: Set your Overleaf password`
  513. } else {
  514. return 'A change to your Overleaf login options'
  515. }
  516. },
  517. title(opts) {
  518. return `Single sign-on disabled`
  519. },
  520. message(opts, isPlainText) {
  521. const loginUrl = `${settings.siteUrl}/login`
  522. let whatDoesThisMeanExplanation = [
  523. `You can still log in to Overleaf using one of our other <a href="${loginUrl}" style="color: #0F7A06; text-decoration: none;">login options</a> or with your email address and password.`,
  524. `If you don't have a password, you can set one now.`,
  525. ]
  526. if (opts.userIsManaged) {
  527. whatDoesThisMeanExplanation = [
  528. 'You now need an email address and password to sign in to your Overleaf account.',
  529. ]
  530. }
  531. const message = [
  532. 'Your group administrator has disabled single sign-on for your group.',
  533. '<br/>',
  534. '<b>What does this mean for you?</b>',
  535. ...whatDoesThisMeanExplanation,
  536. ]
  537. return message.map(m => {
  538. return EmailMessageHelper.cleanHTML(m, isPlainText)
  539. })
  540. },
  541. secondaryMessage(opts) {
  542. return [``]
  543. },
  544. ctaURL(opts) {
  545. return opts.setNewPasswordUrl
  546. },
  547. ctaText(opts) {
  548. return 'Set your new password'
  549. },
  550. })
  551. templates.surrenderAccountForManagedUsers = ctaTemplate({
  552. subject(opts) {
  553. const admin = _.escape(_formatUserNameAndEmail(opts.admin, 'an admin'))
  554. const toGroupName = opts.groupName ? ` to ${opts.groupName}` : ''
  555. return `${
  556. opts.reminder ? 'Reminder: ' : ''
  557. }You’ve been invited by ${admin} to transfer management of your ${
  558. settings.appName
  559. } account${toGroupName}`
  560. },
  561. title(opts) {
  562. const admin = _.escape(_formatUserNameAndEmail(opts.admin, 'an admin'))
  563. const toGroupName = opts.groupName ? ` to ${opts.groupName}` : ''
  564. return `${
  565. opts.reminder ? 'Reminder: ' : ''
  566. }You’ve been invited by ${admin} to transfer management of your ${
  567. settings.appName
  568. } account${toGroupName}`
  569. },
  570. message(opts, isPlainText) {
  571. const admin = _.escape(_formatUserNameAndEmail(opts.admin, 'an admin'))
  572. const managedUsersLink = EmailMessageHelper.displayLink(
  573. 'user account management',
  574. `${settings.siteUrl}/learn/how-to/Understanding_Managed_Overleaf_Accounts`,
  575. isPlainText
  576. )
  577. return [
  578. `Your ${settings.appName} account ${_.escape(
  579. opts.to
  580. )} 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.`,
  581. ]
  582. },
  583. secondaryMessage(opts, isPlainText) {
  584. const transferProjectOwnershipLink = EmailMessageHelper.displayLink(
  585. 'change project owner',
  586. `${settings.siteUrl}/learn/how-to/How_to_Transfer_Project_Ownership`,
  587. isPlainText
  588. )
  589. return [
  590. `<b>What does this mean for you?</b>`,
  591. `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.`,
  592. `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}.`,
  593. `If you think this invitation has been sent in error please contact your group administrator.`,
  594. ]
  595. },
  596. ctaURL(opts) {
  597. return opts.acceptInviteUrl
  598. },
  599. ctaText(opts) {
  600. return 'Accept invitation'
  601. },
  602. greeting() {
  603. return ''
  604. },
  605. })
  606. templates.testEmail = ctaTemplate({
  607. subject() {
  608. return `A Test Email from ${settings.appName}`
  609. },
  610. title() {
  611. return `A Test Email from ${settings.appName}`
  612. },
  613. greeting() {
  614. return 'Hi,'
  615. },
  616. message() {
  617. return [`This is a test Email from ${settings.appName}`]
  618. },
  619. ctaText() {
  620. return `Open ${settings.appName}`
  621. },
  622. ctaURL() {
  623. return settings.siteUrl
  624. },
  625. })
  626. templates.ownershipTransferConfirmationPreviousOwner = NoCTAEmailTemplate({
  627. subject(opts) {
  628. return `Project ownership transfer - ${settings.appName}`
  629. },
  630. title(opts) {
  631. const projectName = _.escape(
  632. SpamSafe.safeProjectName(opts.project.name, 'Your project')
  633. )
  634. return `${projectName} - Owner change`
  635. },
  636. message(opts, isPlainText) {
  637. const nameAndEmail = _.escape(
  638. _formatUserNameAndEmail(opts.newOwner, 'a collaborator')
  639. )
  640. const projectName = _.escape(
  641. SpamSafe.safeProjectName(opts.project.name, 'your project')
  642. )
  643. const projectNameDisplay = isPlainText
  644. ? projectName
  645. : `<b>${projectName}</b>`
  646. return [
  647. `As per your request, we have made ${nameAndEmail} the owner of ${projectNameDisplay}.`,
  648. `If you haven't asked to change the owner of ${projectNameDisplay}, please get in touch with us via ${settings.adminEmail}.`,
  649. ]
  650. },
  651. })
  652. templates.ownershipTransferConfirmationNewOwner = ctaTemplate({
  653. subject(opts) {
  654. return `Project ownership transfer - ${settings.appName}`
  655. },
  656. title(opts) {
  657. const projectName = _.escape(
  658. SpamSafe.safeProjectName(opts.project.name, 'Your project')
  659. )
  660. return `${projectName} - Owner change`
  661. },
  662. message(opts, isPlainText) {
  663. const nameAndEmail = _.escape(
  664. _formatUserNameAndEmail(opts.previousOwner, 'A collaborator')
  665. )
  666. const projectName = _.escape(
  667. SpamSafe.safeProjectName(opts.project.name, 'a project')
  668. )
  669. const projectNameEmphasized = isPlainText
  670. ? projectName
  671. : `<b>${projectName}</b>`
  672. return [
  673. `${nameAndEmail} has made you the owner of ${projectNameEmphasized}. You can now manage ${projectName} sharing settings.`,
  674. ]
  675. },
  676. ctaText(opts) {
  677. return 'View project'
  678. },
  679. ctaURL(opts) {
  680. const projectUrl = `${
  681. settings.siteUrl
  682. }/project/${opts.project._id.toString()}`
  683. return projectUrl
  684. },
  685. })
  686. templates.userOnboardingEmail = NoCTAEmailTemplate({
  687. subject(opts) {
  688. return `Getting more out of ${settings.appName}`
  689. },
  690. greeting(opts) {
  691. return ''
  692. },
  693. title(opts) {
  694. return `Getting more out of ${settings.appName}`
  695. },
  696. message(opts, isPlainText) {
  697. const learnLatexLink = EmailMessageHelper.displayLink(
  698. 'Learn LaTeX in 30 minutes',
  699. `${settings.siteUrl}/learn/latex/Learn_LaTeX_in_30_minutes?utm_source=overleaf&utm_medium=email&utm_campaign=onboarding`,
  700. isPlainText
  701. )
  702. const templatesLinks = EmailMessageHelper.displayLink(
  703. 'Find a beautiful template',
  704. `${settings.siteUrl}/latex/templates?utm_source=overleaf&utm_medium=email&utm_campaign=onboarding`,
  705. isPlainText
  706. )
  707. const collaboratorsLink = EmailMessageHelper.displayLink(
  708. 'Work with your collaborators',
  709. `${settings.siteUrl}/learn/how-to/Sharing_a_project?utm_source=overleaf&utm_medium=email&utm_campaign=onboarding`,
  710. isPlainText
  711. )
  712. const siteLink = EmailMessageHelper.displayLink(
  713. 'www.overleaf.com',
  714. settings.siteUrl,
  715. isPlainText
  716. )
  717. const userSettingsLink = EmailMessageHelper.displayLink(
  718. 'here',
  719. `${settings.siteUrl}/user/email-preferences`,
  720. isPlainText
  721. )
  722. const onboardingSurveyLink = EmailMessageHelper.displayLink(
  723. 'Join our user feedback program',
  724. 'https://forms.gle/DB7pdk2B1VFQqVVB9',
  725. isPlainText
  726. )
  727. return [
  728. `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:`,
  729. `${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!`,
  730. `${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.`,
  731. `${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.`,
  732. `${onboardingSurveyLink} to help us make Overleaf even better!`,
  733. 'Thanks again for using Overleaf :)',
  734. `Lee`,
  735. `Lee Shalit<br />CEO<br />${siteLink}<hr>`,
  736. `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}.`,
  737. ]
  738. },
  739. })
  740. templates.securityAlert = NoCTAEmailTemplate({
  741. subject(opts) {
  742. return `Overleaf security note: ${opts.action}`
  743. },
  744. title(opts) {
  745. return opts.action.charAt(0).toUpperCase() + opts.action.slice(1)
  746. },
  747. message(opts, isPlainText) {
  748. const dateFormatted = moment().format('dddd D MMMM YYYY')
  749. const timeFormatted = moment().format('HH:mm')
  750. const helpLink = EmailMessageHelper.displayLink(
  751. 'quick guide',
  752. `${settings.siteUrl}/learn/how-to/Keeping_your_account_secure`,
  753. isPlainText
  754. )
  755. const actionDescribed = EmailMessageHelper.cleanHTML(
  756. opts.actionDescribed,
  757. isPlainText
  758. )
  759. if (!opts.message) {
  760. opts.message = []
  761. }
  762. const message = opts.message.map(m => {
  763. return EmailMessageHelper.cleanHTML(m, isPlainText)
  764. })
  765. return [
  766. `We are writing to let you know that ${actionDescribed} on ${dateFormatted} at ${timeFormatted} GMT.`,
  767. ...message,
  768. `If this was you, you can ignore this email.`,
  769. `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.`,
  770. `We also encourage you to read our ${helpLink} to keeping your ${settings.appName} account safe.`,
  771. ]
  772. },
  773. })
  774. const GIT_TOKEN_DOCS_URL =
  775. 'https://docs.overleaf.com/integrations-and-add-ons/git-integration-and-github-synchronization/git-integration/git-integration-authentication-tokens#how-to-generate-authentication-tokens'
  776. templates.gitTokenExpiringSoon = NoCTAEmailTemplate({
  777. subject() {
  778. return 'Your Overleaf token is about to expire'
  779. },
  780. title() {
  781. return 'Your token is about to expire'
  782. },
  783. greeting(opts) {
  784. return opts.firstName ? `Hi ${opts.firstName},` : 'Hi,'
  785. },
  786. message(opts, isPlainText) {
  787. const settingsLink = EmailMessageHelper.displayLink(
  788. 'account settings',
  789. `${settings.siteUrl}/user/settings`,
  790. isPlainText
  791. )
  792. const docsLink = EmailMessageHelper.displayLink(
  793. 'our docs',
  794. GIT_TOKEN_DOCS_URL,
  795. isPlainText
  796. )
  797. return [
  798. `One of your Git authentication tokens is about to expire. This means you won't be able to use your token to authenticate when performing git operations.`,
  799. `If you haven't already, you'll need to generate a new token in your ${settingsLink}.`,
  800. `Take a look at ${docsLink} if you need more help.`,
  801. 'All the best,',
  802. 'Team Overleaf',
  803. ]
  804. },
  805. })
  806. templates.gitTokenExpired = NoCTAEmailTemplate({
  807. subject() {
  808. return 'Your Overleaf token has expired'
  809. },
  810. title() {
  811. return 'Token expired'
  812. },
  813. greeting(opts) {
  814. return opts.firstName ? `Hi ${opts.firstName},` : 'Hi,'
  815. },
  816. message(opts, isPlainText) {
  817. const settingsLink = EmailMessageHelper.displayLink(
  818. 'account settings',
  819. `${settings.siteUrl}/user/settings`,
  820. isPlainText
  821. )
  822. const docsLink = EmailMessageHelper.displayLink(
  823. 'our docs',
  824. GIT_TOKEN_DOCS_URL,
  825. isPlainText
  826. )
  827. return [
  828. `One of your Git authentication tokens has expired. This means you won't be able to use it to authenticate when performing git operations.`,
  829. `If you haven't already, you'll need to generate a new token in your ${settingsLink}.`,
  830. `Take a look at ${docsLink} if you need more help.`,
  831. 'All the best,',
  832. 'Team Overleaf',
  833. ]
  834. },
  835. })
  836. templates.SAMLDataCleared = ctaTemplate({
  837. subject(opts) {
  838. return `Institutional Login No Longer Linked - ${settings.appName}`
  839. },
  840. title(opts) {
  841. return 'Institutional Login No Longer Linked'
  842. },
  843. message(opts, isPlainText) {
  844. return [
  845. `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.`,
  846. `To get it going again, you'll need to relink your institutional email address to your ${settings.appName} account via your settings.`,
  847. ]
  848. },
  849. secondaryMessage() {
  850. return [
  851. `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.`,
  852. '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.',
  853. `If you have any questions, please get in touch with our support team at ${settings.adminEmail} or by replying to this email.`,
  854. ]
  855. },
  856. ctaText(opts) {
  857. return 'Update my emails and affiliations'
  858. },
  859. ctaURL(opts) {
  860. return `${settings.siteUrl}/user/settings`
  861. },
  862. })
  863. templates.welcome = ctaTemplate({
  864. subject() {
  865. return `Welcome to ${settings.appName}`
  866. },
  867. title() {
  868. return `Welcome to ${settings.appName}`
  869. },
  870. greeting() {
  871. return 'Hi,'
  872. },
  873. message(opts, isPlainText) {
  874. const logInAgainDisplay = EmailMessageHelper.displayLink(
  875. 'log in again',
  876. `${settings.siteUrl}/login`,
  877. isPlainText
  878. )
  879. const helpGuidesDisplay = EmailMessageHelper.displayLink(
  880. 'Help Guides',
  881. `${settings.siteUrl}/learn`,
  882. isPlainText
  883. )
  884. const templatesDisplay = EmailMessageHelper.displayLink(
  885. 'Templates',
  886. `${settings.siteUrl}/templates`,
  887. isPlainText
  888. )
  889. return [
  890. `Thanks for signing up to ${settings.appName}! If you ever get lost, you can ${logInAgainDisplay} with the email address '${opts.to}'.`,
  891. `If you're new to LaTeX, take a look at our ${helpGuidesDisplay} and ${templatesDisplay}.`,
  892. `Please also take a moment to confirm your email address for ${settings.appName}:`,
  893. ]
  894. },
  895. secondaryMessage() {
  896. return [
  897. `PS. We love talking to our users about ${settings.appName}. Reply to this email to get in touch with us directly, whatever the reason. Questions, comments, problems, suggestions, all welcome!`,
  898. ]
  899. },
  900. ctaText() {
  901. return 'Confirm email'
  902. },
  903. ctaURL(opts) {
  904. return opts.confirmEmailUrl
  905. },
  906. })
  907. templates.welcomeWithoutCTA = NoCTAEmailTemplate({
  908. subject() {
  909. return `Welcome to ${settings.appName}`
  910. },
  911. title() {
  912. return `Welcome to ${settings.appName}`
  913. },
  914. greeting() {
  915. return 'Hi,'
  916. },
  917. message(opts, isPlainText) {
  918. const logInAgainDisplay = EmailMessageHelper.displayLink(
  919. 'log in again',
  920. `${settings.siteUrl}/login`,
  921. isPlainText
  922. )
  923. const helpGuidesDisplay = EmailMessageHelper.displayLink(
  924. 'Help Guides',
  925. `${settings.siteUrl}/learn`,
  926. isPlainText
  927. )
  928. const templatesDisplay = EmailMessageHelper.displayLink(
  929. 'Templates',
  930. `${settings.siteUrl}/templates`,
  931. isPlainText
  932. )
  933. return [
  934. `Thanks for signing up to ${settings.appName}! If you ever get lost, you can ${logInAgainDisplay} with the email address '${opts.to}'.`,
  935. `If you're new to LaTeX, take a look at our ${helpGuidesDisplay} and ${templatesDisplay}.`,
  936. `PS. We love talking to our users about ${settings.appName}. Reply to this email to get in touch with us directly, whatever the reason. Questions, comments, problems, suggestions, all welcome!`,
  937. ]
  938. },
  939. })
  940. templates.removeGroupMember = NoCTAEmailTemplate({
  941. subject(opts) {
  942. return `Your ${settings.appName} account has been removed from ${opts.adminName}’s group`
  943. },
  944. title(opts) {
  945. return `Your ${settings.appName} account has been removed from ${opts.adminName}’s group`
  946. },
  947. greeting() {
  948. return ''
  949. },
  950. message() {
  951. const passwordResetUrl = `${settings.siteUrl}/user/password/reset`
  952. return [
  953. 'Don’t worry, your account and projects are still accessible. But there are a few changes to be aware of:',
  954. '<ul>' +
  955. `<li>Your account will have reverted to a free ${settings.appName} plan.</li>`,
  956. `<li>Any project collaborators have been set to read-only (you can invite one collaborator per project on the free plan).</li>`,
  957. `<li>If you previously logged in via SSO, you’ll need to <a href="${passwordResetUrl}">set a password</a> to access your account.</li>` +
  958. '</ul>',
  959. `If you think this has been done in error, please contact your group admin.`,
  960. `Thanks!`,
  961. `Team ${settings.appName}`,
  962. ]
  963. },
  964. })
  965. templates.taxExemptCertificateRequired = NoCTAEmailTemplate({
  966. subject(opts) {
  967. return `Action required: Tax exemption verification for Overleaf [${opts.ein}]`
  968. },
  969. title() {
  970. return 'Action required: Tax exemption verification'
  971. },
  972. greeting() {
  973. return ''
  974. },
  975. message(opts) {
  976. return [
  977. 'Thanks for letting us know your organization is tax exempt. To confirm this, we need some additional verification.',
  978. 'Please reply to this email with one of the following documents attached:',
  979. '<ul>',
  980. '<li>Your IRS determination letter (for non-profits and similar organizations)</li>',
  981. '<li>Your state resale or exemption certificate</li>',
  982. '</ul>',
  983. `These should match the EIN you provided: ${opts.ein}.`,
  984. 'If you have any questions, let us know by replying to this email.',
  985. '<br/>',
  986. 'Best wishes,',
  987. 'Team Overleaf',
  988. '<br/>',
  989. `Our reference: ${opts.stripeCustomerId}`,
  990. ]
  991. },
  992. })
  993. templates.groupMemberLimitWarning = ctaTemplate({
  994. subject(opts) {
  995. return `Action needed: Your Overleaf group is nearly out of licenses`
  996. },
  997. title(opts) {
  998. return `Action needed: Your Overleaf group is nearly out of licenses`
  999. },
  1000. greeting(opts) {
  1001. return opts.firstName ? `Hi ${opts.firstName},` : 'Hi there,'
  1002. },
  1003. message(opts) {
  1004. return [
  1005. `Your Overleaf group <b>${opts.groupName}</b> is close to its license limit.`,
  1006. `<b>${opts.currentMembers} of ${opts.membersLimit} licenses are in use (${opts.remainingSeats} remaining).</b>`,
  1007. 'Because domain capture is enabled, users from your domain can join automatically via SSO.' +
  1008. '<br/>' +
  1009. '<b>Once all licenses are used, new users won’t be able to join.</b>',
  1010. '<b>What you can do now:</b>',
  1011. '<ul>' +
  1012. '<li>Add more licenses, or</li>' +
  1013. '<li>Remove inactive users to free up licenses</li>' +
  1014. '</ul>',
  1015. ]
  1016. },
  1017. ctaText() {
  1018. return 'Add licenses'
  1019. },
  1020. ctaURL() {
  1021. return `${settings.siteUrl}/user/subscription/group/add-users`
  1022. },
  1023. })
  1024. function _formatUserNameAndEmail(user, placeholder) {
  1025. if (user.first_name && user.last_name) {
  1026. const fullName = `${user.first_name} ${user.last_name}`
  1027. if (SpamSafe.isSafeUserName(fullName)) {
  1028. if (SpamSafe.isSafeEmail(user.email)) {
  1029. return `${fullName} (${user.email})`
  1030. } else {
  1031. return fullName
  1032. }
  1033. }
  1034. }
  1035. return SpamSafe.safeEmail(user.email, placeholder)
  1036. }
  1037. export default {
  1038. templates,
  1039. ctaTemplate,
  1040. NoCTAEmailTemplate,
  1041. buildEmail,
  1042. }