2
我想使用Python更改「收件人」和「發件人」字段的電子郵件地址。到目前爲止,我做了以下工作來閱讀必填字段。任何人都請建議,如何改變他們。Python:修改eml文件中的值(電子郵件標題)
from email.parser import Parser
fp = open('2.eml', 'r+')
headers = Parser().parse(fp)
# Make changes only within a code, Not in to the file. I would like to save given changes for from in to my 2.eml file
headers.replace_header('from', '[email protected]')
print ('To: %s' % headers['to'])
print ('From: %s' % headers['from'])
print ('Subject: %s' % headers['subject'])
謝謝!有用 – jaymin581