我工作的Python腳本來發送電子郵件到我的客戶提供的一項調查顯示BCC不隱藏在Gmail中。我只會發送一封電子郵件,其中包含我所有客戶在BCC字段中的電子郵件,這樣我就不需要遍歷所有電子郵件。一切工作正常,當我測試發送電子郵件到我公司的coleagues還當我發到我的個人電子郵件,但每當我發送到Gmail帳戶時,BCC字段顯示不被隱藏和顯示所有的電子郵件。我發現這個職位Email Bcc recipients not hidden using Python smtplib和嘗試,解決方案,以及,但我使用HTML電子郵件的身體,被證明身體內的電子郵件。任何人都可以幫我解決這個問題嗎?使用Python的smtplib
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
def send_survey_mail():
template_path = 'template.html'
background_path = 'image.png'
button_path = 'image2.png'
try:
body = open(template_path, 'r')
msg = MIMEMultipart()
msg['Subject'] = 'Customer Survey'
msg['To'] = ', '.join(['[email protected]', '[email protected]'])
msg['From'] = '[email protected]'
msg['Bcc'] = '[email protected]'
text = MIMEText(body.read(), 'html')
msg.attach(text)
fp = open(background_path, 'rb')
img = MIMEImage(fp.read())
fp.close()
fp2 = open(button_path, 'rb')
img2 = MIMEImage(fp2.read())
fp2.close()
img.add_header('Content-ID', '<image1>')
msg.attach(img)
img2.add_header('Content-ID', '<image2>')
msg.attach(img2)
s = smtplib.SMTP('smtpserver')
s.sendmail('[email protected]',
['[email protected]', '[email protected]', '[email protected]'],
msg.as_string())
s.quit()
except Exception as ex:
raise ex
send_survey_mail()
我從代碼中刪除了下面一行,然後再次嘗試。現在該電子郵件不會發送到我的客戶的Gmail電子郵件。
msg['Bcc'] = '[email protected]'
是的,我這樣做,鏈接相同的解決方案,但對我來說,我需要身體是HTML,所以當我這樣做的方式,電子郵件地址以及該主題出現在電子郵件的正文上。 – greenFedoraHat