Code Monkey home page Code Monkey logo

Comments (5)

cole avatar cole commented on May 15, 2024

@decaz does the server support SMTPUTF8? Without that extension, headers are limited to ASCII. EDIT: I think even if SMTPUTF8 is unsupported, this text should be encoded as per RFC 2047. I'll look at this.

from aiosmtplib.

cole avatar cole commented on May 15, 2024

Ok, I've added some bugfixes around this to master. You should now be able to use UTF8 chars in the sender or recipient's display name. To have them work in the actual email address, the server needs SMTPUTF8 support.

Note, here you're using Header (legacy python email API) with EmailMessage (new API). If you're using EmailMessage you should be able to do:

    message = EmailMessage()
    message['Subject'] = 'Subject'
    message['From'] = '"Pepé" <[email protected]>'

If you want to use the legacy compat32 API for some reason, it's Message, not EmailMessage, and don't encode the header.

    message = Message()
    message['Subject'] = 'Subject'
    message['From'] = Header('"Pepé" <[email protected]>', 'utf-8')

from aiosmtplib.

decaz avatar decaz commented on May 15, 2024

I've changed nothing in my example code but It gives me the following error:

Traceback (most recent call last):
  File "test_utf8_sender.py", line 19, in <module>
    asyncio.run(main())
  File "/home/decaz/.pyenv/versions/3.7.5/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/home/decaz/.pyenv/versions/3.7.5/lib/python3.7/asyncio/base_events.py", line 579, in run_until_complete
    return future.result()
  File "test_utf8_sender.py", line 15, in main
    await aiosmtplib.send(message, sender, hostname='extra.devel.ifx')
  File "/home/decaz/workspace/aiosmtplib/src/aiosmtplib/api.py", line 397, in send
    message, sender=sender, recipients=recipients
  File "/home/decaz/workspace/aiosmtplib/src/aiosmtplib/smtp.py", line 260, in send_message
    recipients = extract_recipients(message)
  File "/home/decaz/workspace/aiosmtplib/src/aiosmtplib/email.py", line 162, in extract_recipients
    recipients.extend(extract_addresses(recipient))
  File "/home/decaz/workspace/aiosmtplib/src/aiosmtplib/email.py", line 108, in extract_addresses
    return [address.addr_spec for address in header.addresses]
  File "/home/decaz/workspace/aiosmtplib/src/aiosmtplib/email.py", line 108, in <listcomp>
    return [address.addr_spec for address in header.addresses]
AttributeError: 'str' object has no attribute 'addr_spec'

I guess it is because recipient is of string type, not Address instance.

from aiosmtplib.

cole avatar cole commented on May 15, 2024

OK, I've added handling for that case as well to master, I was just looking at the encoding thing before.

That error is happening because you're using a tuple of strings to assign multiple addresses. That assigns a string where an email.headerregistry.Address would normally be. It does seem to work, though.

I would still say it's probably not great practice. There are many ways to generate normal Address objects: you can use a tuple of Address objects directly, assign a string multiple times, or assign a comma seperated string (', '.join). In this case just do message['To'] = '[email protected]'.

from aiosmtplib.

decaz avatar decaz commented on May 15, 2024

Thanks! I think the issue can be closed now.

from aiosmtplib.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.