通过python将HTML表转换为outlook

x6492ojm  于 2023-02-17  发布在  Python
关注(0)|答案(1)|浏览(108)

我需要通过Python发送一个HTML表到Outlook我尝试了这段代码,但它不工作,它给我发送一封空邮件

msg = MIMEMultipart()
    msg['Subject'] = "subject"
    msg['From'] = "from.com"
    msg['To'] = ', '.join(email_list)
    html = """table border="1" class="dataframe"> 
  <thead> 
    <tr style="text-align: right;"> 
      <th>DG Lead</th> 
    </tr> 
  </thead> 
  <tbody> 
    <tr> 
      <td>Krishnamurthy Ramamurthy</td> 
      <td>324</td> 
> 
    <tr> """
    msg.HTMLBody=html
    s = smtplib.SMTP(SERVER)
    s.sendmail("from.com", email_list, msg.as_string())
    s.quit()
dsekswqp

dsekswqp1#

使用Gmail SMTP服务器,这应该对您有效

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# Set up the message parameters
msg = MIMEMultipart()
msg['From'] = 'From@gmail.com'
msg['To'] = 'TO@hotmail.com'
msg['Subject'] = 'Test HTML Email'

# Create the HTML message
html = """<html><body><p>This is a test HTML email!</p><table border="1">
  <tr>
    <th>Header 1</th>
    <th>Header 2</th>
  </tr>
  <tr>
    <td>Cell 1</td>
    <td>Cell 2</td>
  </tr>
</table></body></html>"""
msg.attach(MIMEText(html, 'html'))

# Send the message via Gmail SMTP server
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
server.login('youremail(gmail)', '[app password][1]')  # Replace with your actual password
server.sendmail(msg['From'], msg['To'], msg.as_string())
server.quit()

相关问题