发送一封电子邮件,使我可以在电子邮件正文中编辑个性化内容。例如,我想输入用户电话的5位数分机。然后将其格式化为电子邮件正文。这是我的代码。
def instruct(send):
pass
import smtplib
from email.mime.text import MIMEText
from email.message import EmailMessage
email_user = 'E-mailaddress'
email_send = input('Enter address to Send e-mail to: ')
digits = input('Enter users 5 digit Phone Ext: ') #Users phone ext
subject = 'Voice Mail Instructions '
msg = EmailMessage()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject
#body of e-mail with formatted e-mail message
signature = """\
<html>
<body>
<p>Hi,<br>
Attached Below are instructions for setting up voice mail at your {ext}. Please let me know if you have any questions.<br>
<br>
Thanks<br>
</p>
</body>
</html>
"""
msg.format(ext=digits)
msg.set_content(signature)
filename = 'mypdf.pdf'
with open(filename, 'rb') as content_file:
content = content_file.read()
msg.add_attachment(content, maintype='application/pdf', subtype='pdf', filename=filename)
text = msg.as_string()
server = smtplib.SMTP('mailserver',25)
server.sendmail(email_user, email_send,text)
server.quit
答案 0 :(得分:0)
如果我正确理解了该问题,则希望更改文本以包含用户输入的5位数字,在这种情况下,请尝试:
#body of e-mail with formatted e-mail message
signature = """\
<html>
<body>
<p>Hi,<br>
Attached Below are instructions for setting up voice mail at your extension: {}. Please let me know if you have any questions.<br>
<br>
Thanks<br>
</p>
</body>
</html>
""".format(digits)