This doesn t directly answer the question, but given your response to a comment by "DNS", it might solve your problem.
When sending SMTP mail, you need to understand that the "from" and "to" addresses that you pass to the smtplib.sendmail() routine as arguments are not the same thing as what you see in the From: and To: headers in the message when it s received. Those arguments become parameters given to the receiving SMTP mailer, with the "MAIL FROM" and "RCPT TO" commands. This is commonly referred to as the "envelope" of the mail, and the values usually show up in the Received: header lines.
To specify the headers you want, you have to supply them yourself before the body of the message. The smtplib example shows how that s done, in that case with a tuple called "msg" that they prepend to the message body.