Sending HTML email using Python

前端 未结 10 1150
小鲜肉
小鲜肉 2020-11-22 04:57

How can I send the HTML content in an email using Python? I can send simple text.

10条回答
  •  无人及你
    2020-11-22 05:21

    Actually, yagmail took a bit different approach.

    It will by default send HTML, with automatic fallback for incapable email-readers. It is not the 17th century anymore.

    Of course, it can be overridden, but here goes:

    import yagmail
    yag = yagmail.SMTP("me@example.com", "mypassword")
    
    html_msg = """

    Hi!
    How are you?
    Here is the link you wanted.

    """ yag.send("to@example.com", "the subject", html_msg)

    For installation instructions and many more great features, have a look at the github.

提交回复
热议问题