Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8533367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T09:56:57+00:00 2026-06-11T09:56:57+00:00

I am trying to send an email using the Python email client. I have

  • 0

I am trying to send an email using the Python email client. I have written the following code but it sends the attachemnt as the body and not as an attached file.

Could someone please tell me what is wrong with the code:

    # Import smtplib for the actual sending function
import smtplib

# Here are the email package modules we'll need
from email.mime.text import MIMEText
from email.mime.multipart import MIMEMultipart
from email.mime.application import MIMEApplication


EMAIL_LIST = ['rec@rec.com']

# Create the container (outer) email message.
msg = MIMEMultipart()
msg['Subject'] = 'THIS DOES NOT WORK'
# me == the sender's email address
# family = the list of all recipients' email addresses
msg['From'] = 'send@sender.com'
print EMAIL_LIST
print '--------------------'
print ', '.join(EMAIL_LIST)
msg['To'] = ', '.join(EMAIL_LIST)
msg.preamble = 'THIS DOES NOT WORK'


fileName = 'c:\\p.trf'
with open(fileName, 'r') as fp:
    attachment = MIMEText(fp.read())
    fp.close()
    msg.add_header('Content-Disposition', 'attachment', filename=fileName)
    msg.attach(attachment)


# Send the email via our own SMTP server.
s = smtplib.SMTP('localhost')
s.sendmail('julka@pv.com', EMAIL_LIST, msg.as_string())
s.quit()
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T09:56:58+00:00Added an answer on June 11, 2026 at 9:56 am

    For the attachment, you should probably use, MIMEBase something like this:

    import os
    from email import encoders
    from email.mime.base import MIMEBase
    
    with open(fileName,'r') as fp:
        attachment = MIMEBase('application','octet-stream')
        attachment.set_payload(fp.read())
        encoders.encode_base64(attachment)
        attachment.add_header('Content-Disposition','attachment',filename=os.path.split(fileName)[1])
        msg.attach(attachment)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to send email (Gmail) using python, but I am getting following
I am trying to send email using c# following is my code. try {
I am trying to send an email using the following very standard code. However,
I'm trying to send and save the send email using C# code. But i
I am trying to send an email using c# using the following code. MailMessage
I am trying to send email using the following code and get the error
am trying to send an email using the following code $this->load->library('email', $config); $this->email->from('leena.nasir552@gmail.com'); $this->email->to('leena.nasir@morgan.com');
I am trying to send an email using an Indy Email Client. The body
i am trying to send email using mail chimp api but the following error
I am trying to send email using AJAX and PHP but no success:( My

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.