Is it possible to change the url in the email notifications?

Technical Support
  • I'm running nodebb and another node app on the same server, using a reverse proxy. Due to that, the image links in the posts are relative, and don't display correctly in email notifications.

    Is there any way of running some kind of a script on the {{content}} that will replace all instances of relative links to direct links in the notification email?

    PS. Where all of the template files for notifications are located? They dont seem to be in \src\views\emails\ - I can't find for example the new topic notification there.

  • @Lucas-Severyn I believe emails use "url" property in config.json? check that.

  • Yes, they use {url} for the static stuff, but for the post content they use the actual post content.

    I'd like to adjust the urls in post content (but only in the emails) - I already changed the urls for other elements like link to the user, link to the topic, by hardcoding the leading part.

  • @Lucas-Severyn can you give an example? You shouldn't have to adjust the URLs in the post content. It's supposed to automatically rewrite relative URLs to absolute ones.

  • Sure, for example this is the source code of the email that doesn't display the images:

    in all cases where I have a working link, I actually overrode them in the template

    Here is the email source - notice the indirect image sources:

    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"><style type="text/css">.emoji[data-set-id="emoji-one"]{vertical-align:middle;height:20px;width:20px}</style>
    	<a href="http://dash/board/user/Lucas"><img style="vertical-align: middle; width: 24px; height: 24px; padding-right: 1em;" src="" title="Lucas"></a>
    	<a href="http://dash/board/user/Lucas">Lucas</a> has posted a new topic called &quot;<a href="http://dash/board/topic/15/updated-latest-news">Updated latest news</a>&quot; in &quot;<a href="http://dash/board/category/2/dcl">DCL</a>&quot;:
    •	We probably need .....<br>
    •	No change.... <br>
    •	I assume ....</p>
    <p><img src="/nodebb/uploads/files/1478707630983-upload-606926c6-a083-4817-81c5-bf6732159c6d.png" alt="0_1478707659844_upload-606926c6-a083-4817-81c5-bf6732159c6d" class="img-responsive img-markdown"></p>
    <p><img src="/nodebb/uploads/files/1478707646862-upload-26466cf8-c236-4440-acc7-e80b98f8da05-resized.png" alt="0_1478707675336_upload-26466cf8-c236-4440-acc7-e80b98f8da05" class="img-responsive img-markdown"></p>
    <a href="http://dash/board/topic/15/updated-latest-news">Click here to view the topic</a>

    and here is the template I edited myself - notice the manual overrides to at least make some of the links work:

    	<a href="http://dash/board/user/{user.slug}"><img style="vertical-align: middle; width: 24px; height: 24px; padding-right: 1em;" src="{user.picture}" title="{}" /></a>
    	<a href="http://dash/board/user/{user.slug}">{}</a> has posted a new topic called "<a href="http://dash/board/topic/{topicSlug}">{title}</a>" in "<a href="http://dash/board/category/{category.slug}">{}</a>":
    <a href="http://dash/board/topic/{topicSlug}">Click here to view the topic</a>
  • For the sake of completeness, here is how I solved it.

    I'm not very proud of the solution but it works.

    In the emailer plugin, I added this bit to mailOptions variable.
    Now I need to be very careful not to update the plugin and overwrite the index.js file

     var mailOptions = {
        from: data.from,
        html: data.html.replaceAll ('src="/nodebb/','src="http://dash/nodebb/'),
        text: data.plaintext,
        // subject: data.subject
        subject: combinedTopic

Suggested Topics