Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SMTP sending an priority email

Tags:

python

smtplib

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?

like image 540
Sarah92 Avatar asked Aug 07 '12 09:08

Sarah92


People also ask

How do I send a priority email?

Compose the mail message. Click on “Options,” > “Priority,” and then locate the level of importance to mark this message and click once. Click “Send.”

What does email priority mean?

Most email services and programs use message priorities to designate what's important and what's not. Message priorities can be applied manually or automatically, and you can also mark a message as low priority, or unimportant.

What makes an email high priority?

The 'high priority' sending option is designed to ensure that the recipient of the email knows that this is an important email before opening it and should therefore be prioritised. It may be that the email Page 2 contains urgent information that the recipient may need.

How do you send an email with high importance in Java?

String priority = msg. getHeader("X-Priority", ""); if (priority != null && priority. equals("1")) ... // it's important Similarly for the more standard, but less used, Importance and Priority headers.


1 Answers

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())

Addendum for the values:

According to this forum, there are the following values:

1 (Highest), 2 (High), 3 (Normal), 4 (Low), 5 (Lowest). 3 (Normal) is default if the field is omitted.

like image 166
glglgl Avatar answered Sep 20 '22 05:09

glglgl