New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UTF-8 Email Header #58255
Comments
Hello! I am not a programmer so I appologize if I just don't understand the docs properly. I need to wirte a function which sends emails with utf-8 encoded subject and body. I tried something like this: def sendMail (fromAddr, toAddr, subject, body = '', attachment = ''):
message = email.mime.multipart.MIMEMultipart()
message.add_header('From',fromAddr)
message.add_header('To',toAddr)
message['Subject'] = email.header.Header(subject,'utf-8')
if (body != ''):
msgPart = email.mime.text.MIMEText(body,'plain','utf-8')
message.attach(msgPart)
if (attachment != ''):
if os.path.exists(attachment) == True:
filename = attachment.rpartition(os.sep)[2]
fp = open(attachment,'rb')
msgPart = email.mime.base.MIMEBase('application','octet-stream')
msgPart.set_payload(fp.read())
fp.close()
email.encoders.encode_base64(msgPart)
msgPart.add_header('Content-Disposition','attachment',filename=filename)
message.attach(msgPart)
if smtpPort == 25:
smtpCon = smtplib.SMTP(smtpSrv,smtpPort)
else:
smtpCon = smtplib.SMTP_SSL(smtpSrv,smtpPort)
if (smtpUser != '') and (smtpPass != ''):
smtpCon.login(smtpUser,smtpPass)
smtpCon.send_message(message,mail_options=['UTF8SMTP','8BITMIME'])
logger.info (_('Sent mail to: {0} with subject: {1}').format(toAddr,subject))
smtpCon.quit() I realized that adding email subject this way somehow brokes the message, so that the plain text body of the message is not visible on receiving side. I had to chnage the code like this: base64Subject = base64.b64encode(subject.encode('utf-8')).decode()
encodedSubject = '=?UTF-8?B?{0}?='.format(base64Subject)
message.add_header('Subject',encodedSubject) Am I doing something wrong? |
Hello Michal. This bug tracker is used to collect bug reports and feature requests, not for general support. Please use the python-list mailing list, also known as the comp.lang.python newgroup, or #python on IRC (Freenode), or Stack Overflow, or any other discussion venue. If you do find that the Python docs are erroneous, misleading or incomplete, then feel free to say so and we’ll reopen this report to see how we can improve the docs. Cheers! |
Hello Eric! I believe that there is a bug which prevents adding UTF-8 encoded Best regards Michal Dne 19. února 2012 9:31 Éric Araujo <report@bugs.python.org> napsal(a):
|
Sorry, I cannot right now take the time to go through the doc and your code. Please use any of the friendly venues I listed in my previous message to get help on your code. |
I guess you don't understand me. My script works properly. I don't need any help with it. OK? I have Now, what should I do to report the bug with adding UTF-8 encoded Dne 19. února 2012 9:52 Éric Araujo <report@bugs.python.org> napsal(a):
|
Michal, it's your wording of your report, and also some of the contents that caused Eric's reaction. When you conclude with "Am I doing something wrong?", then your message is *not* a bug report, but a question for help (namely, you are asking somebody to find out whether you did something wrong). Please structure bug reports as follows:
Your report gives hints at 1, but neither discusses 2 or 3. I.e. you say what code you write, but you did not say (AFAICT) what parameters you passed to the function. And you did not say what happened when you passed the parameters. This is important information, as the first step of us is to reproduce the bug report, i.e. try out all your steps and see whether the same happens also when we do it (which often enough is not the case). Since this bug report is already filled with unrelated meta-discussion, please submit a new bug report in the style I explain above. |
Hello Martin! Thanks for your kind words and for giving me hints how to fill the bug Best regards Michal Dne 19. února 2012 19:59 Martin v. Löwis <report@bugs.python.org> napsal(a):
|
I had written a message which read much like Martin’s and wanted to reopen this report, but apparently my flaky connection did not let it go through and now it’s lost. My apologies for not understanding your report for what it was, and thanks for persevering. |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: