简体   繁体   中英

Trying to create an email script, yet not all recipients receive the email

The email sends and shows that it sends to both listed recipients, but only the first listed one actually receives the message. Strange since I don't notice anything particularly wrong with how I entered the addresses in (based on other examples I came across), so I'm looking for another perspective on the issue.

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

email_user = 'myemail@gmail.com'
email_send = 'otheremail1@gmail.com, otheremail2@gmail.com'
subject = 'Test'

msg = MIMEMultipart()
msg['From'] = email_user
msg['To'] = email_send
msg['Subject'] = subject

body = """Hello,

This is a test.

Thanks!"""
msg.attach(MIMEText(body,'plain'))

filename='dataset.csv'
attachment =open(filename,'rb')

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

msg.attach(part)
text = msg.as_string()
server = smtplib.SMTP('smtp.office365.com',587)
server.starttls()
server.login(email_user,'password')

server.sendmail(email_user,email_send,text)
server.quit()
 server.sendmail(email_user,email_send.split(','),text) and remove the space

基本上你只发送了第一个并且需要传递另一个。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM