Python Forum
I get attachment paperclip on email without any attachments
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I get attachment paperclip on email without any attachments
#1
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:

   

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
Reply
#2
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.
Reply
#3
Hi,

Yes, I can view the raw email but I haven't a clue what I'd be looking for... Big Grin
Reply
#4
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!!
Reply
#5
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,
)
Reply
#6
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...
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Unable to download TLS Report attachment blason16 6 533 Feb-26-2024, 07:36 AM
Last Post: Pedroski55
  Extract PDF Attachment from Gmail jstaffon 0 573 Sep-10-2023, 01:55 PM
Last Post: jstaffon
  code to send attachments contained on the drive. stefanoste78 1 849 Oct-12-2022, 02:16 AM
Last Post: Larz60+
  Unable to send email attachments cosmarchy 7 2,534 Mar-09-2022, 09:29 PM
Last Post: bowlofred
  Trying to determine attachment file type before saving off.. cubangt 1 2,139 Feb-23-2022, 07:45 PM
Last Post: cubangt
  Help Needed | Read Outlook email Recursively & download attachment Vinci141 1 4,073 Jan-07-2022, 07:38 PM
Last Post: cubangt
  Sending Attachments via smtplib [SOLVED] AlphaInc 3 2,146 Oct-28-2021, 12:39 PM
Last Post: AlphaInc
  Clicking Every Page and Attachment on Website shoulddt 1 1,730 Jul-09-2021, 01:08 PM
Last Post: snippsat
  ATT00001 instead of PDF attachment to an email dominiklucas 0 3,756 Jul-25-2020, 04:05 PM
Last Post: dominiklucas
  Sending an email with attachment without using SMTP? PythonNPC 5 3,167 May-05-2020, 07:58 AM
Last Post: PythonNPC

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020