-3
email_template = """

<b>Opportunity Summary <a href="{{ opptyURL }}">{{ OpptyNumber }}</a></b><br>
Client: {{ clientName }}<br>
Opportunity Desc: {{ opptyDesc }}<br>
Total TCV (USD): {{ TCV }}<br>
Country: {{ country }}<br>
Geo: {{ geo }}<br>
Market: {{ market }}<br>
Sector: {{ sectorName }}<br>
Industry: {{ sicName }}<br>
OO: {{ ooEmail }}<br>
<br>

enter image description here

In the above code snippet i want to read values from kafka message and insert into email template for example OpportunityNumber read from kafka message and insert into template after replacing all values .send that email template to kafka topic.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245

1 Answers1

0

First, create a Template object, then consume your data and update the template string to create the email string.

Then send emails.

from string import Template

t = Template(...)

consumer = ... # refer your Kafka client documentation
producer = ...

# example from kafka-python. Or replace with database result loop 
for message in consumer:
  # records can be JSON strings, deserialized would make data a dict()
  data = consumer.value()  
  # apply values to template   
  email_body = t.substitute(data)
  # send email
  smtp...

  # or send to kafka
  producer.send('email-topic', email_body) 

The same could be done with Jinja2 or Mako templates instead.

OneCricketeer
  • 179,855
  • 19
  • 132
  • 245