我已经编写了一个功能,可以发送带有附件、文本图像和其他内容的邮件,但现在我需要该功能来使用 de Cc(Carbon Copy)功能,以便将副本发送到不同的电子邮件。
我对该功能进行了一些更改,它可以工作,但不是我想要的。
电子邮件发送到地址(“toaddr”),邮件显示有其他电子邮件添加为抄送(“tocc”)电子邮件,但抄送电子邮件没有收到电子邮件。
为了更清楚(因为我认为我不是很清楚),这是一个例子:
Sender: from@hotmail.com
Receiver: to@hotmail.com
Copied: cc@hotmail.com
to@hotmail.com receives the email and can see that cc@hotmail.com is copied on it.
cc@hotmail.com does not get the email.
if to@hotmail.com reply to all the email, THEN cc@hotmail gets the email.
谁能帮我告诉我我需要改变什么功能?我猜问题出在server.sendmail()
功能上
这是我的功能:
def enviarCorreo(fromaddr, toaddr, tocc, subject, text, file, imagenes):
msg = MIMEMultipart('mixed')
msg['From'] = fromaddr
msg['To'] = ','.join(toaddr)
msg['Cc'] = ','.join(tocc) # <-- I added this
msg['Subject'] = subject
msg.attach(MIMEText(text,'HTML'))
#Attached Images--------------
if imagenes:
imagenes = imagenes.split('--')
for i in range(len(imagenes)):
adjuntoImagen = MIMEBase('application', "octet-stream")
adjuntoImagen.set_payload(open(imagenes[i], "rb").read())
encode_base64(adjuntoImagen)
anexoImagen = os.path.basename(imagenes[i])
adjuntoImagen.add_header('Content-Disposition', 'attachment; filename= "%s"' % anexoImagen)
adjuntoImagen.add_header('Content-ID','<imagen_%s>' % (i+1))
msg.attach(adjuntoImagen)
#Files Attached ---------------
if file:
file = file.split('--')
for i in range(len(file)):
adjunto = MIMEBase('application', "octet-stream")
adjunto.set_payload(open(file[i], "rb").read())
encode_base64(adjunto)
anexo = os.path.basename(file[i])
adjunto.add_header('Content-Disposition', 'attachment; filename= "%s"' % anexo)
msg.attach(adjunto)
#Send ---------------------
server = smtplib.SMTP('localhost')
server.set_debuglevel(1)
server.sendmail(fromaddr,[toaddr,tocc], msg.as_string()) #<-- I modify this with the tocc
server.quit()
return