V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
scienhub
V2EX  ›  问与答

email 的 html 到底应该怎么排版啊

  •  
  •   scienhub · Jun 24, 2024 · 1450 views
    This topic created in 677 days ago, the information mentioned may be changed or developed.

    之前是没搞定用 python+smtp+gmail 发信

    根据这个这个帖子 https://v2ex.com/t/1049187 的建议,用 https://github.com/kootenpv/yagmail 搞定了。

    现在有了 邮件 html 的排版问题。

    我先是用了这个 https://github.com/leemunroe/responsive-html-email-template 模板,啥都不改直接发出去,在 iPhone 的邮件客户端,Thunderbird 客户端,以及 gmail web 客户端上看起来都有问题。

    主要是段落间间距巨大,而且邮件顶部也有巨大的空白,后面有截图。

    发信的代码大概就是

    yag.send(
        to='[email protected]',
        contents=['path/to/email.html'],
    )
    

    然后我在 thunderbird 客户端里直接把 npm 发给我的邮件另存为 html ,然后用 yagmail 发出去,同样排版问题。

    NPM 的邮件 npn email

    我发出去的样子,行间距莫名其妙地大,而且最顶上图标上下都有莫名其妙的巨大空白 my email

    已经被搞破防了,这邮件的排版怎么这么难搞。有没有什么工具可以辅助的呀?

    8 replies    2024-06-26 09:26:13 +08:00
    Jinnrry
        1
    Jinnrry  
       Jun 24, 2024 via Android
    不同邮箱用的 html 标准不一样,但基本上都是用的非常老的标准,不要用任何最近几年的语法
    since2021
        2
    since2021  
       Jun 24, 2024   ❤️ 1
    https://frankindev.com/2022/07/16/available-html-tags-in-emails/
    只有部分的 html 标签在邮件里能用,尽量用简单的标签
    CHTuring
        3
    CHTuring  
       Jun 24, 2024
    想兼容所有的邮箱的话,那就只能用 table 来做。
    kcccc
        4
    kcccc  
       Jun 24, 2024
    看看 MJML ,生成自响应的邮件模板。
    idealist
        5
    idealist  
       Jun 24, 2024   ❤️ 2
    WashFreshFresh
        6
    WashFreshFresh  
       Jun 25, 2024
    关键词 模板引擎 我经常用的就是 java 的 FreeMarker
    yusf
        7
    yusf  
       Jun 25, 2024
    table
    scienhub
        8
    scienhub  
    OP
       Jun 26, 2024
    @kcccc

    感谢,我尝试一下这个工具
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2491 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 43ms · UTC 08:34 · PVG 16:34 · LAX 01:34 · JFK 04:34
    ♥ Do have faith in what you're doing.