How can I send email with custom label

I am using smtplib module to send email, how can write code for sending email with our custom email label? please help.

Were you able to send email at all with smtplib? Where exactly are you getting stuck - what help do you need?

What exactly do you mean by a “custom email label”?

1 Like

I am able to send email via smtplib module but I wan to mark a label as “Secret” to my email, not able to find which option should I use. I can see c# code saying
Header.add(“msip_labels”, “some ascii value”);
Header.add(“somename”, “Restricted - Secret”)

What effect should this have? For example, do you want it to affect how the mail server will handle the mail? Or should it change how the message is displayed for the user? Or something else?

Mail server should handle it.

Okay, and what should it do differently when it sees this “label”?

it does email classification based on this, I am looking for more secure classification to share my data.

If the labels are really just custom headers, then that’s outside the scope of smtplib. How you add the labels depends on how you construct the message in the first place.

Adapted from the smtplib documtentation and your example,

# Add the From: and To: headers at the start!
msg = ("From: %s\r\nTo: %s\r\n"
       % (fromaddr, ", ".join(toaddrs)))

msg += "msip_labels: some ascii value\r\nsomename: Restricted - Secret\r\n"

msg += "\r\n"

msg = "body of message"

server = smtplib.SMTP('localhost')
server.sendmail(fromaddr, toaddrs, msg)