Python Forum
I get attachment paperclip on email without any attachments - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: I get attachment paperclip on email without any attachments (/thread-36672.html)



I get attachment paperclip on email without any attachments - monika_v - Mar-16-2022

Hi,

I'm trying to send a simple email with the code below:

import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
from email.mime.image import MIMEImage
from email.mime.application import MIMEApplication

def send_test_mail(body):
    sender_email = <SenderEmail>
    receiver_email = <ReceiverEmail>

    msg = MIMEMultipart()
    msg['Subject'] = '[Email Test]'
    msg['From'] = sender_email
    msg['To'] = receiver_email
    
    msgText = MIMEText('<b>%s</b>' % (body), 'html')
    msg.attach(msgText)

    try:
        with smtplib.SMTP_SSL('smtp.gmail.com', 587) as smtpObj:
            smtpObj.ehlo()
            smtpObj.login(<LoginUserName>, <LoginPassword>)
            smtpObj.sendmail(sender_email, receiver_email, msg.as_string())
    except Exception as e:
        print(e)
       
if __name__ == "__main__":
    send_test_mail("Welcome to Medium!")
Whe the email is received, I get the paperclip icon indicating there is an attachment when there clearly isn't one:

[attachment=1661]

Python is not my strong point but I'm sure it has more to do with SMTPLIB rather than python.

Does anyone know what is going on here?

Thanks


RE: I get attachment paperclip on email without any attachments - nilamo - Mar-17-2022

It's a multipart message. If you could look at the raw (or "original", depending on your email client), you could see if maybe there was more than one part sent, which the email client is maybe misunderstanding?

That sort of looks like Outlook, which I'm not sure has the option to view the raw email. I'd suggest using gmail to help debug.


RE: I get attachment paperclip on email without any attachments - cosmarchy - Mar-19-2022

Hi,

Yes, I can view the raw email but I haven't a clue what I'd be looking for... Big Grin


RE: I get attachment paperclip on email without any attachments - cosmarchy - Mar-19-2022

If I receive the email using Outlook, I get the attachment paperclip but if I use Thunderbird or the web, I don't get any indication of an attachment.

So, I'm guessing this is something to do with Outlook!!


RE: I get attachment paperclip on email without any attachments - snippsat - Mar-19-2022

I would suggest that you try yagmail.
Make test and general usage a lot easier.
If i do test it work as expected.

Without attachments.
import yagmail

receiver = "[email protected]"
body = "Hello there from Python Forum"
yag = yagmail.SMTP("user_name", 'password')
yag.send(
    to=receiver,
    subject="Python test without attachment",
    contents=body,    
)
With attachments.
Gmail show attachment as a button,a other client show attachment as paperclip.
import yagmail

receiver = "[email protected]"
body = "Hello there from Python Forum"
filename = "test.pdf"
yag = yagmail.SMTP("user_name", 'password')
yag.send(
    to=receiver,
    subject="Python test with attachment",
    contents=body,
    attachments=filename,
)



RE: I get attachment paperclip on email without any attachments - cosmarchy - Mar-19-2022

Just tried yagmail and whilst it looks a lot easier than smtplib, I surprisingly still get the paperclip attachment.

Convinced this is an outlook thing now...