Hack Forums
[Python] Problem with sending HTML email from Python - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] Problem with sending HTML email from Python (/showthread.php?tid=6058240)



Problem with sending HTML email from Python - SIM-4378207 - Mar 19, 2020

Hello,


This is the code I am using: https://pastebin.com/GJQTm7eA


I want to put the subject in the text but as every email has different subject I get them from a spredsheet. I cannot get the subject from the spreadsheet in the HTML version tho.


Anybody has any idea how to do it? In the pastebin is the latest version I came with, but it is buggy.


When it sends an email there is blank line between html and the subject and between the subject and html2


RE: Problem with sending HTML email from Python - webdev77 - Mar 19, 2020

What is the solution you found?

Please don't destroy site content via the edit feature. If people continue to do that, further restrictions could be a result.


RE: Problem with sending HTML email from Python - SIM-4378207 - Mar 19, 2020

(Mar 19, 2020 12:04 PM)webdev77 Wrote:  What is the solution you found?

Please don't destroy site content via the edit feature. If people continue to do that, further restrictions could be a result.

My bad.

Old code:
Code
html = """\
    <html>
      <head></head>
      <body>
        <p>Hello,<br>
           I am aaaa and I represent aaaaa<br>
           We are a aaaa site for aaaaaaa.<br>
           We would like to collaborate</p>
      </body>
    </html>
    """

    html2 = """\
    <html>
      <head></head>
      <body>
        <p>. Please get back to us  
        </p>
      </body>
    </html>
    """

    html = html + all_subjects[idx] + html2

Working code:

Code
html = """Hello,<br>
           I am aaaa and I represent aaaaa<br>
           We are a aaaa site for aaaaaaa.<br>
           We would like to collaborate for """

    html2 = """<html>Please get back to us  
    </html>"""

    html = html + all_subjects[idx] + html2

The head and the body from the html were ruining it. I removed them as I don't really need them, this is a simple email. I just needed to put my signature in there.