Hello Python community :)
This is my first post so don`t judge strictly.

I need the user's client to start, so that the user may edit the message and decide himself whether he clicks on the Send button to really send it.

I have searched on google and most code are for Windows OS only. Can`t find anything for Mac OS. I personaly using Win but doing my project for Mac OS.

6 Years
Discussion Span
Last Post by radc

Ok, I though about this. I am using Tkinter and I know how to create a window with some widgets including Send button. But, I have quiestion then. My programme should send an attached file. So then user clicks on a name of object, programme should identify selcted name, find it in the directory and attach it to the mail window.
visually it is supposed to be like this: user clicks on name from list of names, presses the button 'Send mail', appears a mail window with already attached file so the user can see it. After editing some message, user presses button 'Send' and it is done.
So how to implement this?


When I send my email, I receive an empty message with no picture. Any ideas?
Here is the code:

import smtplib
import base64

filename = "D:\\test.png"
receiver = "my.email@gmail.com"
body = ""
subject = ""

def sendTO(filename,receiver,body,subject):
    fo = open(filename, "rb")
    filecontent = fo.read()
    encodedcontent = base64.b64encode(filecontent)

    sender = 'my.email@gmail.com'

    marker = "AUNIQUEMARKER"
    # Define the main headers.
    part1 = """From: From Person <me@fromdomain.net>
    To: To Person <%s>
    Subject: %s
    MIME-Version: 1.0
    Content-Type: multipart/mixed; boundary=%s
    """ % (receiver,subject,marker, marker)

    part2 = """Content-Type: text/plain
    """ % (body,marker)

    # Define the attachment section
    part3 = """Content-Type: multipart/mixed; name=\"%s\"
    Content-Disposition: attachment; filename=%s
    """ %(filename, filename, encodedcontent, marker)
    message = part1 + part2 + part3

    username = "my username"
    password = "my pass"

    server = smtplib.SMTP('smtp.gmail.com:587')
    server.sendmail(sender, receiver, message)
    print "Successfully sent email"
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.