我已经编写了一个功能,发送带有附件的邮件,文本上的图像和其他东西,但现在我需要使用的功能,以使用抄送(抄送)功能,以发送副本到不同的电子邮件。
我已经对函数做了一些更改,它可以工作,但不是我想要的。
THe电子邮件发送到地址("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发布于 2012-04-26 03:30:49
在sendmail调用中,您传递的是[toaddr, tocc],这是一个列表列表,您是否尝试过传递toaddr + tocc?
https://stackoverflow.com/questions/10322203
复制相似问题