首页 > 解决方案 > 需要使用 python 发送带有 HTML 格式文本的电子邮件

问题描述

此代码可以发送包含投资基金信息的格式化电子邮件。但是当有多个 idk 如何发送它时。

我试图附加到一个列表,而不是在使用 HTML 发送之后对其进行格式化。但它不工作

#"""Use pandas to format the table Guia de Fundos"""
import pandas as pd
import PySimpleGUI as sg
import yagmail


df = pd.read_csv("HERE GOES ONE SPREAD SHEET USING AS DB")
df = df.set_index('CNPJ', drop = False)

# Very basic window.  Return values as a list

layout = [`
          [sg.Text('Entre os dados a seguir, Nome, E-mail')],
          [sg.Text('CNPJ do Fundo', size=(25, 1)), sg.InputText('')],      
          [sg.Text('Nome do Cliente', size=(25, 1)), sg.InputText('')],      
          [sg.Text('E-mail do Cliente', size=(25, 1)), sg.InputText('')],            
          [sg.Submit(), sg.Cancel()]      
         ]

window = sg.Window('Opção de Investimento').Layout(layout)         
button, values = window.Read()
window.Close()

print(button, values[0], values[1], values[2])
#'TO TEST USE THIS CNPJ 18860180000147'
text_input = int(values[0])
Nome_cliente = values[1]
email_cliente = values[2]

df = df.loc[text_input]  
print(df['FUNDO'], df['Aplicação Inicial'], df['Desde_Início'], 
df['Liquidez_total_(CotizaçãoLiquidação)'], df['CVM'], df['Tributação'])

name = df['FUNDO']
rentabilidade = df['Desde_Início']
liquidez = df['Liquidez_total_(CotizaçãoLiquidação)']
categoria = df['CVM']
aplicacaomin = df['Aplicação Inicial']

sg.PopupScrolled("""
    Nome do Cliente: {0}
    E-mail: {1}
    Fundo: {2}
    Rentabilidade: {3}
    Liquidez: {4}
    Categoria: {5}
    Aplicacao Minima: {6}""".format(Nome_cliente, email_cliente, name, 
    rentabilidade, liquidez, categoria, aplicacaomin), 
    title='Verificar', yes_no=True)

"""Get information from the table Guia de FUndos and send an email"""

yagmail.register('YOUR E-MAIL', 'PASSWORD')
yag = yagmail.SMTP('YOUR E-MAIL')

contents = ['''
<html>                                                            
<body align="center" style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%; width: 100%; height: 100%; margin: 0; padding: 0; background-color: #06202e;">                  
                     <tr>
                        <img src="https://d335luupugsy2.cloudfront.net/cms/files/68608/1552053344/$aw5o0p8ghll" alt="" width="173" border="0" style="max-width: 1674px; border: 0; -ms-interpolation-mode: bicubic; height: auto; outline: none; text-decoration: none; vertical-align: bottom;" class="img-max">
                     </tr>
                                                   <table width="100%" border="0" cellspacing="0" cellpadding="0" style="-webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; mso-table-lspace:0pt; mso-table-rspace:0pt; border-collapse:collapse !important;">
                                                       <p>
                                                            <li style="line-height: 150%;"><span style="font-size: 12px; color: #ffffff;">Ola {5}, conforme conversado segue opcao de investimento... </span></li>
                                                      </p>
                                                      <tr>
                                                         <td bgcolor="#072738" align="left" style="-webkit-text-size-adjust:100%; -ms-text-size-adjust:100%; mso-table-lspace:0pt; mso-table-rspace:0pt; font-size: 16px; line-height: 150%; font-family: Helvetica, Arial, sans-serif; color: #666666; padding: 9px 18px; word-break: break-word !important;" class="padding">
                                                            <p style="line-height: 150%;"><span style="font-size: 13px; color: #ffffff;"><strong> {0}  (Lamina em Anexo)</strong></span></p>
                                                            <ul>
                                                               <li style="line-height: 150%;"><span style="font-size: 12px; color: #ffffff;"> Rentabilidade: {1}  CDI (Acumulada)</span></li>
                                                               <li style="line-height: 150%;"><span style="font-size: 12px; color: #ffffff;">IR: respeita a tabela regressiva de renda fixa (come cotas)</span></li>
                                                               <li style="line-height: 150%;"><span style="font-size: 12px; color: #ffffff;">Liquidez: D+{2}</span></li>
                                                               <li style="line-height: 150%;"><span style="font-size: 12px; color: #ffffff;">Categoria: {3}</span></li>
                                                              <li style="line-height: 150%;"><span style="font-size: 12px; color: #ffffff;">Aplicação Minima: {4}</span></li>
                                                            </ul>

                                                         </td>
                                                      </tr>
                                                   </table>             
</body>
</html>

'''.format(name, rentabilidade, liquidez, categoria, aplicacaomin, Nome_cliente)]
"""You can add attachments=filename, to send with the email."""
yag.send(email_cliente, 'SUBJECT', contents)

因此,如果有人可以提供帮助。我需要发送更多的资金。今天这个代码只能用一个基金发送。

电子邮件示例:

-今天

你好 ....

基金1信​​息...

-预期的

你好 ....

基金1信​​息...

基金2信息...

基金3资料...

标签: pythonhtmlpython-3.x

解决方案


推荐阅读