Python Forum
Question on HTML formatting with set string in message
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Question on HTML formatting with set string in message
#1
Hi guys,

I am wondering if anyone can help me format this email so that I just get a bolded: Here are the new jobs from Tethers Unlimited: and then the remaining jobs that populate the email are plain text. I am having a difficult time with the HTML and variable calling because I'm not sure how to manipulate the variable to pull it out of a Set[str] when I can only concatenate strings.

Here is the code:
def send_email(jobs):
    import smtplib, ssl
    from email.mime.text import MIMEText
    from email.mime.multipart import MIMEMultipart

    port = 465
    password = "XXXX"
    sender_email = "XXXX"
    receiver_email = "XXXX"
    linebreak = '\n'

    message = MIMEMultipart("alternative")
    message["Subject"] = "Tethers Unlimited Jobs"
    message["From"] = sender_email
    message["To"] = receiver_email

    text = f"""\
Here are the new jobs from Tethers Unlimited:\n{linebreak.join(jobs)}"""
    html ="""
<html>
    <body>
        <p><b>Here are the new jobs from Tethers Unlimited:</b><br>
        """ + {linebreak.join(jobs)} + """
        </p>
    </body>
</html>
"""
    part1 = MIMEText(text,"plain")
    part2 = MIMEText(html,"html")
    message.attach(part1)
    message.attach(part2)
    context = ssl.create_default_context()
    with smtplib.SMTP_SSL("smtp.gmail.com", port, context=context) as server:
        server.login("[email protected]", password)
        server.sendmail(sender_email, receiver_email, message.as_string())
Here is the error I get when I run it:

Error:
C:\Python34\venv\Scripts\python.exe C:/Users/Cknut/venv/PersonalCrawlers/TethersUnlimited.py Traceback (most recent call last): File "C:/Users/Cknut/venv/PersonalCrawlers/TethersUnlimited.py", line 22, in <module> send_email(job_list_split) File "C:\Users\Cknut\venv\PersonalCrawlers\send_email.py", line 19, in send_email html =""" TypeError: can only concatenate str (not "set") to str Process finished with exit code 1
buran write Mar-08-2021, 08:59 AM:
Please, use proper tags when post code, traceback, output, etc. This time I have added tags for you.
See BBcode help for more info.
Reply


Messages In This Thread
Question on HTML formatting with set string in message - by Cknutson575 - Mar-08-2021, 06:59 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  String to List question help James_Thomas 6 987 Sep-06-2023, 02:32 PM
Last Post: deanhystad
  Need to replace a string with a file (HTML file) tester_V 1 775 Aug-30-2023, 03:42 AM
Last Post: Larz60+
  Formatting a date time string read from a csv file DosAtPython 5 1,297 Jun-19-2023, 02:12 PM
Last Post: DosAtPython
  syntax error question - string mgallotti 5 1,325 Feb-03-2023, 05:10 PM
Last Post: mgallotti
  String formatting (strptime) issues Henrio 2 843 Jan-06-2023, 06:57 PM
Last Post: deanhystad
  Tkinterweb (Browser Module) Appending/Adding Additional HTML to a HTML Table Row AaronCatolico1 0 934 Dec-25-2022, 06:28 PM
Last Post: AaronCatolico1
  confused about string formatting barryjo 7 2,001 Mar-06-2022, 02:03 AM
Last Post: snippsat
Big Grin General programming question (input string)[ jamie_01 2 1,607 Jan-08-2022, 12:59 AM
Last Post: BashBedlam
  string formatting barryjo 7 2,074 Jan-02-2022, 02:08 AM
Last Post: snippsat
  Help with string formatting in classes brthurr 6 9,364 Dec-17-2021, 04:35 PM
Last Post: Jeff900

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020