2017-03-25 12 views
0

저는 파이썬 스크립트를 사용하여 고객과 설문 조사를 통해 이메일을 보냅니다. 숨은 참조 란에 모든 고객의 이메일이 포함 된 이메일을 하나만 보내어 모든 이메일을 반복하지 않아도됩니다. 회사의 동료에게 이메일을 보내고 내 개인 이메일로 보낸 메일을 테스트 할 때 모든 것이 잘 작동하지만 Gmail 계정으로 보낼 때마다 숨은 참조 필드는 숨겨져 있지 않고 모든 이메일을 표시합니다. 나는이 게시물 Email Bcc recipients not hidden using Python smtplib을 발견하고 그 해결책을 시도했지만 html 본문 이메일을 사용함에 따라 이메일이 본문에 표시되었습니다. 아무도 이것에 나를 도울 수 있습니까?BCC가 python smtplib을 사용하여 Gmail에 숨겨져 있지 않습니다.

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]' 

답변

0

msg [ 'BCC'] 입력란을 정의하지 않으셨습니까? 해당 필드를 설정하면 해당 필드가 강제로 포함됩니다. 숨은 참조 전자 메일 주소가 sendmail 명령의 대상 주소 목록에 있어야합니다. 살펴보기 this post

+0

예, 링크를 동일한 솔루션,하지만 내 경우에는 내가, HTML을 수 그래서 그 방법을 수행 이메일 주소를 몸을 필요로했다 제목도 이메일 본문에 표시됩니다. – greenFedoraHat

0

msg [ 'To'] 또는 msg [ 'Cc']에는 bcc 메일이 없습니다. 단지 server.sendmail()에서 할

import smtplib 
from email.mime.multipart import MIMEMultipart 
from email.mime.text import MIMEText 
from email.mime.base import MIMEBase 
from email import encoders 

from_addr = "[email protected]" 
to_addr = ["[email protected]", "[email protected]"] 

msg = MIMEMultipart() 

msg['From'] = from_addr 
msg['To'] = to_addr 
msg['Subject'] = "SUBJECT" 

body = "BODY" 

msg.attach(MIMEText(body, 'plain')) 

filename = "FILE.pdf" 
attachment = open('/home/FILE.pdf', "rb") 

part = MIMEBase('application', 'octet-stream') 
part.set_payload((attachment).read()) 
encoders.encode_base64(part) 
part.add_header('Content-Disposition', "attachment; filename= %s" % filename) 

msg.attach(part) 

server = smtplib.SMTP('.....', 587) 
server.starttls() 
server.login(from_addr, 'yourpass') 
text = msg.as_string() 
server.sendmail(from_addr, to_addr + [[email protected]], text) 
server.quit()