Ganesh Kumar
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    1
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Avoid logging into Listmonk for Newsletter Quality Check. Use this hack instead How I Added Discord Preview Feature to Our Listmonk? How we schedule weekly emails ? How to receive email Preview in the Discord server? ## The Hurdle We have set up a system of doing a **mini-research** every week. Each one of the team members takes up a mini-unknown area. We learn about it, create a **solution**, and if it's good then transform it into a blog so that others may **benefit** from it. We wanted to keep the data with us. So, We set up a **[Blogging platform](https://journal.hexmos.com/)** using **[Ghost Blog ](https://ghost.org/)**. As the quality of the content got a little better people started recognizing and subscribing to our blog. Once we had 50+ subscribers it was evident that we needed to set up a newsletter system. Ghost came with a newsletter setup, but we had to pay for **[MailChimp](https://mailchimp.com/)** to use that, to avoid that we set up a self-hosted Email manager **[Listmonk](https://listmonk.app/)** on our own. we had to spend a week coming up with a sync system for migrating subscribers. We set up a sync system and migrated all the Ghost subscribers to Listmonk subscribers so that we can make an automated scheduled newsletter every week. ## Scheduling Newsletter We wanted a scheduled newsletter for every Monday, as the writing would be finished by Sunday. We thought of making it automated so it does not depend on manually sending it and made use of a **[Cron job](https://kubernetes.io/docs/concepts/workloads/controllers/cron-jobs/)** for automation. We have one more newsletter called 365 Reasons which will be sent throughout the year. (banner) The script is fully automated, but we prefer to do a quality check before a campaign sends emails to dozens of recipients. We should not send spam or corrupted emails, it is wasting a person's time. Logging in every time would consume our **precious time**. Since this is a daily chore, we wanted to make it easy on ourselves Listmonk didn't have an integrated solution to this, so we came up with our idea i.e. Sending a snapshot of the HTML before sending the newsletter. ## How I Implemented a Preview We use a **[Jinja](https://jinja.palletsprojects.com/en/3.1.x/)** template for rendering the post, we fetch the last week's posts from our blog. Render the post using a template. In the end, we have an HTML Posted to the Listmonk server. We fetch the scheduled Email and take a Screenshot of it. I used **[Pyppeteer](https://pypi.org/project/pyppeteer/)** library to get a screenshot of the HTML before sending it. ### Getting Preview I have a function that takes the **[Campaign ID](https://listmonk.app/docs/apis/campaigns/)** as input and sends a screenshot to the Discord server. In `send_discord_preview_notification` function, it gets an HTML response and and inputted into `send_discord_notification`function. If there is an error in getting a response then the `log_message` function will send an error message to our Discord server. ```python LIST_MONK_URL = lm.example.com # Give Your LM Url def send_discord_preview_notification(id): # This will send Screenshot of HTML file to discord server url = f"{LIST_MONK_URL}/api/campaigns/{id}/preview" try: response = requests.get(url, headers=lm_headers) response.raise_for_status() # This will raise an HTTP error if the response was an HTTP error except requests.exceptions.RequestException as e: send_discord_notification(f"An error occurred: {e}") else: if response.status_code == 200: send_screenshot_file(response) # This will initiate Screenshot sending feature else: log_message(f"Failed to fetch data. Status code: {response.status_code}") ``` ### Temporary File Handling The `send_screenshot_file` function takes the response as input and sends a screenshot to discord server. I used the **[Temporary directory](https://docs.python.org/3/library/tempfile.html)** for storing the temp file generated while taking a Screenshot of the campaign. The response is written inside `temp_file_path` in .html format in the temporary directory. Initiate **[Asynchronous operation](https://docs.python.org/3/library/asyncio.html)** to take a screenshot of temp.html file by `screenshot` function and save a screenshot in `screenshot_path`. The Screenshot saved in `screenshot_path` is posted to the discord server. ```python import tempfile WEBHOOK_CHANNEL_URL = "https://discord.com/api/webhooks/121fwebwefuik9886/Zffwuica" # Give Your Webhook def send_screenshot_file(response): with tempfile.TemporaryDirectory() as tmpdirname: temp_file_path = f"{tmpdirname}/temp.html" with open(temp_file_path, "wb") as temp_file: temp_file.write(response.encode()) # Directly encode the string screenshot_path = f"{tmpdirname}/Screenshot.png" asyncio.run(screenshot(screenshot_path, f"file://{temp_file_path}")) with open(screenshot_path, "rb") as img: response = requests.post(WEBHOOK_CHANNEL_URL, files={"file": img}) ``` ### Screenshot I tried many other solutions but it didn't go well some of them were sending previews before images were loaded and others only dent half of the preview. Finally, came up with using `Pyppeteer` library. This Library didn't give any problems in the preview. This function will load HTML in the browser take a screenshot of it and save it in **`screenshot_path`**. ```python import asyncio from pyppeteer import launch async def screenshot(screenshot_path, temp_file_path): browser = await launch() page = await browser.newPage() await page.goto(temp_file_path) await page.screenshot({"path": screenshot_path, "fullPage": True}) await browser.close() ``` <img src="https://hackmd.io/_uploads/r1cnt_rlA.png" width="50%"> <img src="https://hackmd.io/_uploads/BJ_kodSeR.png" width="50%"> ## Conclusion My solution s My Preview feature reduced the time for checking scheduled Emails. Using it our team also can give a review for new production Emails.

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully