SMTP sends priority email

I am trying to use Python smtplib to set email priority to high. I have successfully used this library to send emails, but I'm not sure how to get priority.

  import smtplib from smtplib import SMTP 

My first attempt was to use this to research how to set priority:

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

However, I received an error message: keyword priority is not recognized.

I also tried using:

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

However, I get one more error. Is there a way to set priority using only smtplib?

+6
source share
1 answer

Priority is only a matter of email content (more precisely, the content of the header). See here .

The next question will be how to put this in an email.

It completely depends on how you create this letter. If you use the email module, you should do it as follows:

 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()) 
+15
source

Source: https://habr.com/ru/post/922264/


All Articles