我正在尝试使用密件抄送发送电子邮件
我的测试稿
if form_email.is_valid():
toaddr = form_email.cleaned_data['email']
tocc = form_email.cleaned_data['cc_email']
subject = form_email.cleaned_data['subject']
message = form_email.cleaned_data['message']
signature = form_email.cleaned_data['signature']
msgHtml = message + '<br><br>' + signature
SMTPserver = 'smtp.gmail.com'
toaddr = [toaddr]
tocc = [tocc]
user_bcc = [user_bcc]
msg = MIMEMultipart('alternative')
msg['From'] = email_user
msg['To'] = ', '.join(toaddr)
msg['Cc'] = ', '.join(tocc)
#msg['Bcc'] = bcc
msg['Bcc'] = ', '.join(user_bcc)
msg['Subject'] = subject
msg.attach(MIMEText(msgHtml, 'html'))
try:
conn = SMTP(SMTPserver)
conn.set_debuglevel(False)
conn.login(email_user, gmail_app_pass)
conn.sendmail(email_user, toaddr, msg.as_bytes())
conn.quit()
except:
conn.quit()
messages.warning(request, 'Something went wrong, Email not sent', extra_tags='alert')
return redirect(reverse('detail', kwargs={"album_id": album_id}))
messages.success(request, 'Email sent')
return redirect(reverse('detail', kwargs={"album_id": album_id}))
当我在发送的电子邮件中或从收件人的收件箱中打开时,显示“密件抄送”,但第一个不是密件抄送,第二个在“密件抄送”的电子邮件中是“收件箱中没有电子邮件”。
某些信息直接来自数据库