views:

43

answers:

0

Hi...this is my first post so let me know if there are any common courtesies I should know about.

I just started programming 8 months ago, so I am fairly new. I have been doing some projects to get better. A project I'm working on now creates an Excel sheet from inputted data. It's in Python, which I just started learning a couple of weeks ago. I'm attempting to embed part of this Excel sheet into an email, sent from my school address. I have spent hours looking this up, and to no avail.

There are two problems I am asking for help with:

1) The following code works for sending email from GMail, but not my school account. Unfortunately, I have been having a problem setting up outgoing email for this account on my iPhone as well. It may be related? Would anyone have idea why this code doesn't work?

import smtplib
from email.MIMEText import MIMEText

LOGIN = 'myemailaddress'
PASSWORD = 'mypassword'


def send_email(subject, message, from_addr=LOGIN, to_addr=LOGIN):
    msg = MIMEText(message)
    msg['Subject'] = subject
    msg['From'] = from_addr
    msg['To'] = to_addr

    server = smtplib.SMTP('myhost',465)
    server.ehlo()
    server.starttls()
    server.ehlo()
    server.login(LOGIN,PASSWORD)
    server.sendmail(from_addr, to_addr, msg.as_string())
    server.close()


if __name__=="__main__":
    send_email('test', 'This is a test email', "myemailaddress", "myemailaddress")

2) Excel has an option of saving a sheet as a HTML. When doing so, I copy and pasted the HTML source and emailed it as an attachment. Unfortunately, the colored text did not transfer over. Does anyone know of a better way of using Python to send an excel sheet embedded in an email?

Thanks for your help!