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.

Re: Send mail via mail client using Python script 80 80

Making one simple text window to edit the email and one send button should not be so difficult. Then you can use the email module(http://docs.python.org/library/email-examples.html).

Re: Send mail via mail client using Python script 80 80

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?

Re: Send mail via mail client using Python script 80 80

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
    --%s
    """ % (receiver,subject,marker, marker)

    part2 = """Content-Type: text/plain
    Content-Transfer-Encoding:8bit
    
    %s
    --%s
    """ % (body,marker)

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

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

    server = smtplib.SMTP('smtp.gmail.com:587')
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(username,password)
    server.sendmail(sender, receiver, message)
    server.quit()
    print "Successfully sent email"
Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.