0
我已經編寫了一個函數發送郵件與文字,圖像上的文字和其他東西,但現在我需要函數使用de抄送(抄送)功能,以發送副本到不同的電子郵件。Python發送郵件與Cc
我已經做了一些改變的功能,它的作品,但不是我想要的。
電子郵件發送到地址(「toaddr」),郵件顯示有其他電子郵件作爲抄送(「tocc」)電子郵件添加,但抄送電子郵件不收到電子郵件。這裏
更清楚(因爲我覺得我不是很清楚)是一個例子:
Sender: [email protected]
Receiver: [email protected]
Copied: [email protected]
[email protected] receives the email and can see that [email protected] is copied on it.
[email protected] does not get the email.
if [email protected] reply to all the email, THEN [email protected] gets the email.
誰能幫助我,告訴我,我需要改變對函數什麼??我guees問題與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
它沒有工作! – mauguerra 2012-04-25 21:31:59
我測試了錯誤...其實它確實工作....謝謝 – mauguerra 2012-04-26 14:27:17