发送了电子邮件,让我的电子邮件的正文中编辑个性化内容。比如我想输入用户手机的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
如果我理解正确的问题,你要改变的文本包括由用户的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)