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

Sending attachment fails #228

Open
uklop opened this issue Apr 5, 2022 · 6 comments · May be fixed by #277
Open

Sending attachment fails #228

uklop opened this issue Apr 5, 2022 · 6 comments · May be fixed by #277

Comments

@uklop
Copy link

uklop commented Apr 5, 2022

Thanks for making yagmail.
I'm running yagmail-0.15.277 on python 3.10.

I can't seem to attach a file to my email.
The email arrives just fine but without attachment.

In the code, shown below, I'm sending it to my protonmail account, also when I try to send to a gmail it also fails.

here's the code:

import yagmail
import os

textattach = os.path.join(os.getcwd(), 'test.txt')
print(textattach)

yag = yagmail.SMTP(user='[email protected]', password='hunter2')
#sending the email
yag.send(to='[email protected]', 
	subject='The subject is bla bla bla', 
	contents='Please find the text file attached', 
	attachments=textattach)

print("Email was sent")

The output is as follows:

C:\Users\RegularUsername\Documents\Scripts\email\test.txt
Email was sent

When opening the path (C:\Users\RegularUsername\Documents\Scripts\email\test.txt) it shows the txt file.

@uklop
Copy link
Author

uklop commented Apr 6, 2022

After some more troubleshooting I found the problem was with protonmail.
In gmail the attached file shows up, no problem.
In protonmail the attached file doesn't show up.

@kootenpv
Copy link
Owner

kootenpv commented Apr 6, 2022

cool, thanks for finding that out

if someone wants to dig into this we could maybe find a way that supports both gmail and protonmail

@uklop
Copy link
Author

uklop commented Apr 6, 2022

Interestingly there's some other stuff I found.
If I send it to my gmail, using the script, there's no issue.
If I forward that email from my gmail to protonmail, there's no issue.

I've also got automatic forwarding set up from my gmail to protonmail.
The email that was automatically forwarded from gmail to protonmail doesn't show the attachment.
If I forward the email from my own gmail to my own gmail, thus triggering the autoforward. There's no issue.

The issue seems to be specifically when sending an email from python using yagmail to protonmail.

@NeonDaniel
Copy link

I'm using this package to send diagnostic emails to users. A user got the following response from Proton Mail support and shared it with me (Neon AI refers to the email sent with yagmail):

1. The "Content-Type" email header field.
 
The correct file name formats seem to be the following:
name="example.txt"
filename="UTF-8 encoded file name"
 
However, Neon AI used the following:
name*=utf-8''voice_log.txt
 
2. The "Content-Disposition" email header field.
 
<Neon AI> should add this field for their attachments.
 
3. The "MIME-Version" email header field.
 
Looks like the "MIME-Version: 1.0" header should not appear in the attachment's email header fields.
 
4. Comparison.
 
Yahoo
Content-Type: text/plain
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="=?UTF-8?b?ZXhhbXBsZS50eHQ?="
Content-ID: <[email protected]>
 
MSFT
Content-Type: text/plain; name="example.txt"
Content-Transfer-Encoding: base64
Content-Description: example.txt
Content-Disposition: attachment; filename="example.txt"; size=4;
    creation-date="Tue, 27 Aug 2024 08:08:55 GMT";
    modification-date="Tue, 27 Aug 2024 08:09:02 GMT"
 
Gmail
Content-Type: text/plain; filename="example.txt"; name="example.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="example.txt"; name="example.txt"
Content-ID: <f_m0c4qkcl0>
 
Proton
Content-Type: text/plain; filename="example.txt"; name="example.txt"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="example.txt"; name="example.txt"
 
Neon AI
Content-Type: text/plain; name*=utf-8''voice_log.txt
MIME-Version: 1.0
Content-Transfer-Encoding: base64

ProtonMail support noted that Gmail handles these headers properly but that they are in an "incorrect format", so it appears they do not plan on handling it on their end.

@kootenpv
Copy link
Owner

kootenpv commented Sep 4, 2024

@NeonDaniel thanks for posting, though from your post it's not clear to me what should be fixed still.

If you make a pull request with the correct format, I can push a new version.

@NeonDaniel
Copy link

@NeonDaniel thanks for posting, though from your post it's not clear to me what should be fixed still.

If you make a pull request with the correct format, I can push a new version.

I am also not entirely sure what changes are necessary to make the headers match what ProtonMail expects. I will try to find time to dig in though. Glad you're still maintaining this package 🙂

@NeonDaniel NeonDaniel linked a pull request Oct 18, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

3 participants