SMTP sending an priority email

只谈情不闲聊 提交于 2019-12-04 18:54:12

问题


I am trying to use Python's smtplib to set the priority of an email to high. I have successfully used this library to send email, but am unsure how to get the priority working.

 import smtplib
 from smtplib import SMTP

My first attempt was to use this from researching how to set the priority:

smtp.sendmail(from_addr, to_addr, msg, priority ="high")

However I got an error: keyword priority is not recognized.

I have also tried using:

msg['X-MSMail-Priority'] = 'High'

However I get another error. Is there any way to set the priority using only smtplib?


回答1:


Priority is just a matter of email content (to be exact, header content). See here.

The next question would be how to put that into an email.

That completely depends how you build that email. If you use the email module, you would do it this way:

from email.Message import Message
m = Message()
m['From'] = 'me'
m['To'] = 'you'
m['X-Priority'] = '2'
m['Subject'] = 'Urgent!'
m.set_payload('Nothing.')

and then use it with

smtp.sendmail(from_addr, to_addr, m.as_string())


来源:https://stackoverflow.com/questions/11843148/smtp-sending-an-priority-email

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!