Example #1
0
def _sendEmail_():
    # Open a plain text file for reading.  For this example, assume that
    # the text file contains only ASCII characters.
    #fp = open(textfile, 'rb')
    fp = open('<file>,'rb')
    url_file = MIMEText(fp.read(),'<file_type>') # file_type could be text, html, javascript, pdf
    
    # Create a text/plain message
    #msg = MIMEText(fp.read()) # for text file
    msg = MIMEMultipart()
    fp.close()
    print "in else"
    #print url_file
    notes = MIMEText('Notes: <custom message in the body>','plain')
    #content="""\Test message"""

    # me == the sender's email address
    # you == the recipient's email address
    sender = '*****@*****.**'
    to  = '[email protected];[email protected];[email protected];[email protected]'
    msg['Subject'] = 'test file using python'
    msg['From'] = sender 
    msg['To'] = to
    #msg['Cc'] = cc
    msg.attach(notes)
    msg.attach(url_file)
    print('To:', msg['to'])
    print('From:', msg['from'])
    print('Subject:', msg['subject'])

    # Send the message via our own SMTP server, but don't include the
    # envelope header.
#'''
    server = 'smtp.it.<org>.com' #"email server"
    port  = 25
    s = smtplib.SMTP(server,port)
    s.ehlo()
    s.starttls()
    s.ehlo()
    s.login('<email_id>', '<password>')
    s.sendmail(sender, to,  msg.get_content_maintype())
    s.quit()