Skip to content
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

Can't send message (KeyError) #4

Closed
stefanodvx opened this issue Nov 22, 2023 · 7 comments
Closed

Can't send message (KeyError) #4

stefanodvx opened this issue Nov 22, 2023 · 7 comments

Comments

@stefanodvx
Copy link

HI! I'm trying to send a message... This is my current code (without the login part)

recipients = ["email@proton.me"]
subject = "My first message"
body = "Ciao!"  # html or just text

new_message = proton.create_message(
    recipients=recipients,
    subject=subject,
    body=body
)

sent_message = proton.send_message(new_message)

...and this is the error i get

C:\Users\Stefano\Desktop\test>py -3.11 proton.py
login success
C:\Users\Stefano\AppData\Local\Programs\Python\Python311\Lib\site-packages\pgpy\constants.py:192: CryptographyDeprecationWarning: IDEA has been deprecated
  bs = {SymmetricKeyAlgorithm.IDEA: algorithms.IDEA,
C:\Users\Stefano\AppData\Local\Programs\Python\Python311\Lib\site-packages\pgpy\constants.py:194: CryptographyDeprecationWarning: CAST5 has been deprecated
  SymmetricKeyAlgorithm.CAST5: algorithms.CAST5,
C:\Users\Stefano\AppData\Local\Programs\Python\Python311\Lib\site-packages\pgpy\constants.py:195: CryptographyDeprecationWarning: Blowfish has been deprecated
  SymmetricKeyAlgorithm.Blowfish: algorithms.Blowfish,
C:\Users\Stefano\AppData\Local\Programs\Python\Python311\Lib\site-packages\protonmail\pgp.py:71: UserWarning: Selected compression algorithm not in key preferences
  encrypted_message = str(public_key.encrypt(message))
Traceback (most recent call last):
  File "C:\Users\Stefano\Desktop\test\proton.py", line 24, in <module>
    sent_message = proton.send_message(new_message)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Stefano\AppData\Local\Programs\Python\Python311\Lib\site-packages\protonmail\client.py", line 253, in send_message
    response = self._post(
               ^^^^^^^^^^^
KeyError: 'Sent'
@opulentfox-29
Copy link
Owner

Hello, at the moment it is not possible to send a message to address @proton.me/@protonmail.com because this requires additional encryption.
For now, use a different address.

@stefanodvx
Copy link
Author

@opulentfox-29 tried again sending email to a gmail.com address. now i dont get any error, and i get a Message object back. but no message is sent? I checked both proton and gmail accounts, there's nothing sent.

@opulentfox-29
Copy link
Owner

I can’t know why this happened, if the code worked without errors, then the letter should have been sent, maybe you changed your account settings?
I test it on a clean, newly created account and everything works, it sends emails to Gmail and Tempmail.
try to create a new account and check on it, and you can also look at drafts, because before sending a email, it created draft.

my code:

from protonmail import ProtonMail

username = "...@proton.me"
password = "..."

proton = ProtonMail()
proton.login(username, password)

private_key = '...@proton.me-....asc'
passphrase = '...'
proton.pgp_import(private_key, passphrase=passphrase)

recipients = ["...@gmail.com", "...@bustayes.com"]
subject = "My first message"
body = "Ciao!"  # html or just text

new_message = proton.create_message(
    recipients=recipients,
    subject=subject,
    body=body
)

sent_message = proton.send_message(new_message)

image
image
image

@Jaden024
Copy link

Jaden024 commented Mar 9, 2024

Is there a way to send the message without the signature attached?

@opulentfox-29
Copy link
Owner

Is there a way to send the message without the signature attached?

This will now be the default.
#6

@opulentfox-29
Copy link
Owner

@stefanodvx maybe there was a problem with the private key, in the new version 1.4.0 all keys are received automatically, try sending a message now to gmail.com

Install

pip install protonmail-api-client==1.4.0

Use

from protonmail import ProtonMail

username = "YouAddress@proton.me"
password = "YourPassword123"

proton = ProtonMail()
proton.login(username, password)

recipients = ["to@gmail.com"]
subject = "My first message"
body = "<html><body>hello, i sent my first mail!</body></html>"

new_message = proton.create_message(
    recipients=recipients,
    subject=subject,
    body=body
)

sent_message = proton.send_message(new_message)

also do not forget that gmail can identify all letters from protonmail as spam\scam, check your spam folder. and all the messages you sent in protonmail are not in the “inbox” folder, but in the "sent" folder or in the "all mail" folder
if the message could not be sent, maybe there will be a draft

@stefanodvx
Copy link
Author

works. ty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants