【发布时间】:2021-06-27 07:19:52
【问题描述】:
我在 Python 中创建了一个函数,它将构建一个 html 格式的电子邮件,并通过一个接受匿名电子邮件发送的 Exchange 服务器匿名发送。
但是,CC 列表中的任何人都不会获得副本,只有 TO 列表中的 FIRST 人会获得副本。我尝试使用“逗号”和“分号”作为电子邮件分隔符,但都不起作用。奇怪的是,在收到的电子邮件中可以看到所有电子邮件地址(并且格式正确),尽管只有一个人(收件人列表中列出的第一个人)获得了副本。
这是我的代码
def send_email(sender, subject, sendAsDraft = True): # sendAsDraft not implemented
global toEmail
global ccEmail
# create the email message
htmlFile = open(saveFolder + '\\' + htmlReportBaseName + '.html',encoding = 'utf-8')
message = htmlFile.read().replace('\n', '')
message = message.replace(chr(8217), "'") # converts a strange single quote into the standard one
message = message.replace("'",''') # makes a single quote html friendly
htmlFile.close()
# get the email body text
emailBody = open('emailBody.txt')
bodyText = emailBody.read()
emailBody.close()
now = dt.datetime.today().replace(second = 0, microsecond = 0)
timeStr = returnReadableDate(now) # returns the date as a string in the 'normal' reading format
# insert the current date/time into the marker in the email body
bodyText = bodyText.replace('xxxx', timeStr)
# insert the email body text into the HTML
message = message.replace('xxxx', bodyText)
msg = MIMEMultipart('Report Email')
msg['Subject'] = subject
msg['From'] = sender
msg['To'] = '; '.join(toEmail)
msg['Cc'] = '; '.join(ccEmail)
msg.add_header('Content-Type','text/html')
msg.set_payload(message)
# complete the email send
message = ''
try:
smtpObj = sl.SMTP('1.2.3.4:5') # obviously IP address anonymised
smtpObj.sendmail(sender, '; '.join(toEmail), msg.as_string())
message = 'Email successfully sent'
except:
message = 'Email could not be sent due to an error'
finally:
# write the outcome to the Instance log
global InstanceLog
# write the log
log(InstanceLog, message)
# close object and exit function
smtpObj.quit()
问题可能出在电子邮件服务器上吗?未经身份验证的电子邮件只能发送给一个人?一方面这看起来很奇怪,另一方面又有意义。
谢谢大家。
西米
【问题讨论】: